From 9423ae40fab360a9da317a43d4481b908a74cda5 Mon Sep 17 00:00:00 2001 From: Alexander Vakrilov Date: Wed, 21 Feb 2018 13:07:26 +0200 Subject: [PATCH] test: Fixed unstable timer test (#5449) --- tests/app/timer/timer-tests.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/app/timer/timer-tests.ts b/tests/app/timer/timer-tests.ts index 6b1d98fd3..5125f41b2 100644 --- a/tests/app/timer/timer-tests.ts +++ b/tests/app/timer/timer-tests.ts @@ -113,16 +113,18 @@ export function test_setTimeout_callbackShouldBeCleared() { export function test_setInterval_callbackCalledDuringPeriod(done) { let counter = 0; const expected = 4; + const timeLimit = 300; const start = TKUnit.time(); // >> timer-set-expression const id = timer.setInterval(() => { // >> (hide) counter++; - if (counter === 4) { + if (counter === expected) { const end = TKUnit.time(); timer.clearInterval(id); - done(end - start > 250 ? new Error('setInterval too slow.') : null); + const time = end - start; + done(time > timeLimit ? new Error(`setInterval too slow. Actual time: ${time} timelimit: ${timeLimit}`) : null); } // << (hide) }, 50);