Watchdog class with 4 Vitest tests (27 total now), wired into ctx.heartbeat in the runner. One watchdog per room with a 60s timeout; firing logs an error, marks the room's dashboard tile as errored, and triggers the abort signal so the scenario unwinds. Watchdogs are explicitly stopped in the runner's finally block so pending timers don't keep the node process alive on exit. Also fixes a multi-game bug discovered during stress scenario verification: after a game ends sessions stay parked on the game_over screen, which hides the lobby and makes a subsequent #create-room-btn click time out. runOneMultiplayerGame now navigates every session to / before each game — localStorage auth persists so nothing re-logs in. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
45 lines
1.0 KiB
TypeScript
45 lines
1.0 KiB
TypeScript
/**
|
|
* Watchdog — simple per-room timeout detector.
|
|
*
|
|
* `start()` begins a countdown. `heartbeat()` resets it. If the
|
|
* countdown elapses without a heartbeat, `onTimeout` fires once
|
|
* (subsequent heartbeats are no-ops after firing, unless `start()`
|
|
* is called again). `stop()` cancels any pending timer.
|
|
*
|
|
* Used by the runner to detect stuck rooms: one watchdog per room,
|
|
* scenarios call ctx.heartbeat(roomId) at each progress point, and
|
|
* a firing watchdog logs + aborts the run.
|
|
*/
|
|
|
|
export class Watchdog {
|
|
private timer: NodeJS.Timeout | null = null;
|
|
private fired = false;
|
|
|
|
constructor(
|
|
private timeoutMs: number,
|
|
private onTimeout: () => void,
|
|
) {}
|
|
|
|
start(): void {
|
|
this.stop();
|
|
this.fired = false;
|
|
this.timer = setTimeout(() => {
|
|
if (this.fired) return;
|
|
this.fired = true;
|
|
this.onTimeout();
|
|
}, this.timeoutMs);
|
|
}
|
|
|
|
heartbeat(): void {
|
|
if (this.fired) return;
|
|
this.start();
|
|
}
|
|
|
|
stop(): void {
|
|
if (this.timer) {
|
|
clearTimeout(this.timer);
|
|
this.timer = null;
|
|
}
|
|
}
|
|
}
|