diff --git a/apps/automated/src/timer/timer-tests.ts b/apps/automated/src/timer/timer-tests.ts index 99c633828..e24cb5d8c 100644 --- a/apps/automated/src/timer/timer-tests.ts +++ b/apps/automated/src/timer/timer-tests.ts @@ -171,6 +171,31 @@ export function test_setInterval_callbackCalledWithExtraArgs(done) { ); } +export function test_setInterval_callbackNotDelayedByBusyWork() { + let calls = 0; + + function busyWait(ms: number) { + const waitStart = Date.now(); + while (true) { + if (Date.now() - waitStart >= ms) { + break; + } + } + } + let firstCall = true; + const id = timer.setInterval(() => { + calls++; + if (firstCall) { + firstCall = false; + busyWait(25); + } + }, 50); + + TKUnit.wait(0.11); + timer.clearInterval(id); + TKUnit.assertEqual(calls, 2, 'Callback should be called multiple times with busy wait'); +} + export function test_setInterval_callbackShouldBeCleared(done) { const start = TKUnit.time(); // >> timer-set-interval