GameClockScheduler checks every live game once a second and ends those whose running clock has reached zero, whether or not anyone is connected. The clock replaces the offline turn timeout and the inactivity rule, so both are removed with the offline times they used.
23 lines
875 B
TypeScript
23 lines
875 B
TypeScript
import { GameClockScheduler } from "../../src/game/GameClockScheduler";
|
|
|
|
describe("GameClockScheduler", () => {
|
|
beforeEach(() => jest.useFakeTimers());
|
|
afterEach(() => jest.useRealTimers());
|
|
|
|
it("ends games out of time on every interval until stopped", () => {
|
|
const gameManager = { endGamesOutOfTime: jest.fn() };
|
|
const scheduler = new GameClockScheduler(gameManager, 1_000);
|
|
scheduler.start();
|
|
scheduler.start(); // starting twice does not run it twice
|
|
|
|
jest.advanceTimersByTime(999);
|
|
expect(gameManager.endGamesOutOfTime).not.toHaveBeenCalled();
|
|
jest.advanceTimersByTime(2_001);
|
|
expect(gameManager.endGamesOutOfTime).toHaveBeenCalledTimes(3);
|
|
|
|
scheduler.stop();
|
|
jest.advanceTimersByTime(10_000);
|
|
expect(gameManager.endGamesOutOfTime).toHaveBeenCalledTimes(3);
|
|
});
|
|
});
|