Skip to content

Commit

Permalink
Fix race in test
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany committed Apr 9, 2024
1 parent 1ec83e6 commit 40c50aa
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions ee/control/control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ func TestControlServiceFetch_WithControlRequestIntervalUpdate(t *testing.T) {
stores, err := storageci.MakeStores(t, nopMultislogger.Logger, db)
require.NoError(t, err)
flagController := flags.NewFlagController(nopMultislogger.Logger, stores[storage.AgentFlagsStore])
flagController.SetControlRequestInterval(5 * time.Second) // this is the minimum value
startingRequestInterval := 5 * time.Second // this is the minimum value
flagController.SetControlRequestInterval(startingRequestInterval)
testKnapsack := knapsack.New(stores, flagController, db, nopMultislogger, nopMultislogger)

// Init the test client
Expand All @@ -295,13 +296,13 @@ func TestControlServiceFetch_WithControlRequestIntervalUpdate(t *testing.T) {

// Start running and wait at least a couple request intervals for the change to be applied
go service.Start(context.TODO())
time.Sleep(2 * service.requestInterval)

// Confirm request interval was updated as expected
require.Equal(t, expectedInterval, service.requestInterval)
time.Sleep(2 * startingRequestInterval)

// Stop the service
service.Interrupt(errors.New("test error"))

// Confirm request interval was updated as expected
require.Equal(t, expectedInterval, service.requestInterval)
}

func TestControlServicePersistLastFetched(t *testing.T) {
Expand Down

0 comments on commit 40c50aa

Please sign in to comment.