Skip to content

Commit

Permalink
test: fix a data race in MachineStatusSnapshotController unit tests
Browse files Browse the repository at this point in the history
Fix the flaky test due to the race caused by the test ending before the last log, `task finished`, is written by the task runner.

Signed-off-by: Utku Ozdemir <utku.ozdemir@siderolabs.com>
  • Loading branch information
utkuozdemir committed Jun 7, 2024
1 parent 0965091 commit 5a4251c
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ type MachineStatusSnapshotControllerSuite struct {
}

func (suite *MachineStatusSnapshotControllerSuite) TestReconcile() {
ctx, cancel := context.WithTimeout(suite.ctx, time.Second*5)
defer cancel()

require := suite.Require()

suite.startRuntime()

// wait for the runtime to stop, including all controllers and the tasks they started.
// this is necessary to prevent a data race on the test logger when a task finishes after the test ends.
suite.T().Cleanup(suite.wg.Wait)

ctx, cancel := context.WithTimeout(suite.ctx, time.Second*5)
suite.T().Cleanup(cancel)

siderolinkEventsCh := make(chan *omni.MachineStatusSnapshot)

suite.Require().NoError(suite.runtime.RegisterQController(omnictrl.NewMachineStatusSnapshotController(siderolinkEventsCh)))
Expand Down

0 comments on commit 5a4251c

Please sign in to comment.