Skip to content
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

Fix flaky test Test_runDispatcher/gateway_actions_passed #5405

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions internal/pkg/agent/application/managed_mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ func Test_runDispatcher(t *testing.T) {
name string
mockGateway func(chan []fleetapi.Action) *mockGateway
mockDispatcher func() *mockDispatcher
interval time.Duration
flushInterval time.Duration
contextTimeout time.Duration
skipOnWindowsReason string
}{{
name: "dispatcher not called",
Expand All @@ -87,7 +88,8 @@ func Test_runDispatcher(t *testing.T) {
dispatcher := &mockDispatcher{}
return dispatcher
},
interval: time.Second,
flushInterval: time.Second,
contextTimeout: time.Millisecond * 100,
}, {
name: "gateway actions passed",
mockGateway: func(ch chan []fleetapi.Action) *mockGateway {
Expand All @@ -101,7 +103,8 @@ func Test_runDispatcher(t *testing.T) {
dispatcher.On("Dispatch", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Once()
return dispatcher
},
interval: time.Second,
flushInterval: time.Second,
contextTimeout: time.Millisecond * 200,
}, {
name: "no gateway actions, dispatcher is flushed",
mockGateway: func(ch chan []fleetapi.Action) *mockGateway {
Expand All @@ -115,7 +118,8 @@ func Test_runDispatcher(t *testing.T) {
dispatcher.On("Dispatch", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Maybe() // allow a second call in case there are timing issues in the CI pipeline
return dispatcher
},
interval: time.Millisecond * 60,
flushInterval: time.Millisecond * 60,
contextTimeout: time.Millisecond * 100,
}}

for _, tc := range tests {
Expand All @@ -130,9 +134,9 @@ func Test_runDispatcher(t *testing.T) {
detailsSetter := func(upgradeDetails *details.Details) {}
acker := &mockAcker{}

ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*100)
ctx, cancel := context.WithTimeout(context.Background(), tc.contextTimeout)
defer cancel()
runDispatcher(ctx, dispatcher, gateway, detailsSetter, acker, tc.interval)
runDispatcher(ctx, dispatcher, gateway, detailsSetter, acker, tc.flushInterval)
assert.Empty(t, ch)

gateway.AssertExpectations(t)
Expand Down