From 24a1ecc0544a4a516e8e3173cac372ea57dcf030 Mon Sep 17 00:00:00 2001 From: Exoridus Date: Sat, 26 Sep 2026 08:07:49 +0200 Subject: [PATCH] test(core): freeze the clock in the default minSlice coroutine test --- test/core/coroutine-system.test.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/core/coroutine-system.test.ts b/test/core/coroutine-system.test.ts index 42af1770d..222df805c 100644 --- a/test/core/coroutine-system.test.ts +++ b/test/core/coroutine-system.test.ts @@ -484,6 +484,9 @@ describe('CoroutineSystem', () => { }); test('defaults minSlice to a 64th of the bound frame target', () => { + // The slice is ~130 us of wall clock; a stalled runner would spend it + // before the coroutine reads it, so the clock is frozen. + const now = vi.spyOn(performance, 'now').mockReturnValue(1000); const system = new CoroutineSystem({ budget: seconds(0) }); const seen: number[] = []; @@ -494,8 +497,8 @@ describe('CoroutineSystem', () => { }); frame(system, frameBudget(0)); + now.mockRestore(); - expect(seen[0]).toBeGreaterThan(0); - expect(seen[0]).toBeLessThanOrEqual(1 / 120 / 64); + expect(seen[0]).toBeCloseTo(1 / 120 / 64, 12); }); });