test: speed up agent container websocket close test (#25559)

`TestWatchAgentContainers/CoderdWebSocketCanHandleClientClosing` spent
about 15 seconds waiting for the real websocket heartbeat ticker to
detect that the client closed.

Add a clock-aware `HeartbeatClose` wrapper and pass `api.Clock` through
the containers watch handler so the test can drive the heartbeat
deterministically with `quartz.Mock`. The test still verifies the same
client-close teardown path, but it advances the heartbeat tick instead
of waiting for wall-clock time.

Refs #25557


Discovered as part of the work on CODAGT-381.
This commit is contained in:
Ethan
2026-05-22 20:10:25 +10:00
committed by GitHub
parent ca1f6b19a2
commit 705421bc5d
3 changed files with 19 additions and 2 deletions
+1 -1
View File
@@ -871,7 +871,7 @@ func (api *API) watchWorkspaceAgentContainers(rw http.ResponseWriter, r *http.Re
ctx, wsNetConn := codersdk.WebsocketNetConn(ctx, conn, websocket.MessageText)
defer wsNetConn.Close()
go httpapi.HeartbeatClose(ctx, logger, cancel, conn)
go httpapi.HeartbeatCloseWithClock(ctx, logger, cancel, conn, api.Clock)
encoder := json.NewEncoder(wsNetConn)