add tests

This commit is contained in:
Eduardo Speroni
2020-11-16 13:54:48 -03:00
parent 32801e9fe3
commit ae455ed977

View File

@ -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