mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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:
@@ -21,6 +21,12 @@ func HeartbeatClose(ctx context.Context, logger slog.Logger, exit func(), conn *
|
||||
heartbeatCloseWith(ctx, logger, exit, conn, quartz.NewReal(), HeartbeatInterval)
|
||||
}
|
||||
|
||||
// HeartbeatCloseWithClock is like HeartbeatClose, but uses the provided
|
||||
// clock so tests can drive heartbeat ticks deterministically.
|
||||
func HeartbeatCloseWithClock(ctx context.Context, logger slog.Logger, exit func(), conn *websocket.Conn, clk quartz.Clock) {
|
||||
heartbeatCloseWith(ctx, logger, exit, conn, clk, HeartbeatInterval)
|
||||
}
|
||||
|
||||
func heartbeatCloseWith(ctx context.Context, logger slog.Logger, exit func(), conn *websocket.Conn, clk quartz.Clock, interval time.Duration) {
|
||||
ticker := clk.NewTicker(interval, "HeartbeatClose")
|
||||
defer ticker.Stop()
|
||||
|
||||
Reference in New Issue
Block a user