mirror of
https://github.com/coder/coder.git
synced 2026-06-05 22:18:20 +00:00
test: fix TestAgentConnectionMonitor_PingTimeout race with mock assertions (#19836)
Fixes https://github.com/coder/internal/issues/970 The test doesn't wait for `monitor()` to complete, and the mock database call that we assert takes place in a `defer` within `monitor()`. This allows the mock assertions to race with the defer and flake the test. Solution is to explicitly wait for `monitor()` to complete before the end of the test, so that mock assertions (which happen in a `t.Cleanup()`) don't race.
This commit is contained in:
@@ -150,9 +150,14 @@ func TestAgentConnectionMonitor_PingTimeout(t *testing.T) {
|
||||
AnyTimes().
|
||||
Return(database.WorkspaceBuild{ID: build.ID}, nil)
|
||||
|
||||
go uut.monitor(ctx)
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
uut.monitor(ctx)
|
||||
close(done)
|
||||
}()
|
||||
fConn.requireEventuallyClosed(t, websocket.StatusGoingAway, "ping timeout")
|
||||
fUpdater.requireEventuallySomeUpdates(t, build.WorkspaceID)
|
||||
_ = testutil.TryReceive(ctx, t, done) // ensure monitor() exits before mDB assertions are checked.
|
||||
}
|
||||
|
||||
func TestAgentConnectionMonitor_BuildOutdated(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user