- 
                Notifications
    You must be signed in to change notification settings 
- Fork 0
Add options structs and timeouts to orch package #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b10547b
              c3458e1
              7123f78
              a61fb21
              31e741a
              a6463e2
              bf0df09
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package orch | ||
|  | ||
| import ( | ||
| "context" | ||
| "errors" | ||
| "testing" | ||
| "time" | ||
|  | @@ -11,7 +12,7 @@ import ( | |
|  | ||
| func TestNewController(t *testing.T) { | ||
| t.Run("nil clientset returns error", func(t *testing.T) { | ||
| controller, err := NewController(nil, nil) | ||
| controller, err := NewController(nil, nil, nil) | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All tests currently use the default options. In the future, we may want to add tests to experiment with multiple combinations. The defaults are very sane, so I doubt we will deviate much. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume that means testing scheduling with two executors or with a timeout or with different watcher options. It may be ok to defer these, although eventually it would be good to test for instance that a second test can be scheduled when you have two executors, and so on. | ||
| if err == nil { | ||
| t.Errorf("no error returned for nil clientset") | ||
| } | ||
|  | @@ -50,15 +51,15 @@ func TestControllerSchedule(t *testing.T) { | |
|  | ||
| for _, tc := range cases { | ||
| t.Run(tc.description, func(t *testing.T) { | ||
| controller, _ := NewController(fake.NewSimpleClientset(), nil) | ||
| controller, _ := NewController(fake.NewSimpleClientset(), nil, nil) | ||
| executor := &executorMock{} | ||
| controller.newExecutorFunc = func() Executor { | ||
| return executor | ||
| } | ||
|  | ||
| if tc.start { | ||
| controller.Start() | ||
| defer controller.Stop(0) | ||
| defer controller.Stop(context.Background()) | ||
| } | ||
|  | ||
| err := controller.Schedule(tc.session) | ||
|  | @@ -84,9 +85,9 @@ func TestControllerSchedule(t *testing.T) { | |
|  | ||
| func TestControllerStart(t *testing.T) { | ||
| t.Run("sets running state", func(t *testing.T) { | ||
| controller, _ := NewController(fake.NewSimpleClientset(), nil) | ||
| controller, _ := NewController(fake.NewSimpleClientset(), nil, nil) | ||
| controller.Start() | ||
| defer controller.Stop(0) | ||
| defer controller.Stop(context.Background()) | ||
| if controller.Stopped() { | ||
| t.Errorf("Stopped unexpectedly returned true after starting controller") | ||
| } | ||
|  | @@ -112,7 +113,7 @@ func TestControllerStart(t *testing.T) { | |
|  | ||
| for _, tc := range cases { | ||
| t.Run(tc.description, func(t *testing.T) { | ||
| controller, _ := NewController(fake.NewSimpleClientset(), nil) | ||
| controller, _ := NewController(fake.NewSimpleClientset(), nil, nil) | ||
| controller.waitQueue = newQueue(limitlessTracker{}) | ||
|  | ||
| if tc.mockNL != nil { | ||
|  | @@ -121,7 +122,7 @@ func TestControllerStart(t *testing.T) { | |
|  | ||
| if tc.mockPW != nil { | ||
| controller.pw = tc.mockPW | ||
| controller.watcher = NewWatcher(tc.mockPW) | ||
| controller.watcher = NewWatcher(tc.mockPW, nil) | ||
| } | ||
|  | ||
| err := controller.Start() | ||
|  | @@ -170,7 +171,7 @@ func TestControllerStop(t *testing.T) { | |
|  | ||
| for _, tc := range cases { | ||
| t.Run(tc.description, func(t *testing.T) { | ||
| controller, _ := NewController(fake.NewSimpleClientset(), nil) | ||
| controller, _ := NewController(fake.NewSimpleClientset(), nil, nil) | ||
| controller.running = true | ||
| controller.waitQueue = newQueue(limitlessTracker{}) | ||
|  | ||
|  | @@ -196,7 +197,11 @@ func TestControllerStop(t *testing.T) { | |
|  | ||
| go controller.loop() | ||
| time.Sleep(timeout) | ||
| err := controller.Stop(tc.stopTimeout) | ||
|  | ||
| ctx, cancel := context.WithTimeout(context.Background(), tc.stopTimeout) | ||
| defer cancel() | ||
|  | ||
| err := controller.Stop(ctx) | ||
| if tc.shouldError && err == nil { | ||
| t.Errorf("executors unexpectedly finished before timeout") | ||
| } else if !tc.shouldError && err != nil { | ||
|  | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if it is best to make the ControllerOptions parameter a pointer. It allows someone to specify nil and inherit defaults, but it decreases the readability of function calls. It may be better to have callers specify
ControllerOptions{}to inherit the defaults. I believe I have seen both with Kubernetes. Would love input here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it is too important. If it is not a pointer you would write ControllerOptions{} where you now write nil, and it avoids some logic inside the controller, so it may be a reasonable thing to do.