mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
test: Fixed unstable timer test (#5449)
This commit is contained in:

committed by
GitHub

parent
4ce45666a5
commit
9423ae40fa
@ -113,16 +113,18 @@ export function test_setTimeout_callbackShouldBeCleared() {
|
|||||||
export function test_setInterval_callbackCalledDuringPeriod(done) {
|
export function test_setInterval_callbackCalledDuringPeriod(done) {
|
||||||
let counter = 0;
|
let counter = 0;
|
||||||
const expected = 4;
|
const expected = 4;
|
||||||
|
const timeLimit = 300;
|
||||||
|
|
||||||
const start = TKUnit.time();
|
const start = TKUnit.time();
|
||||||
// >> timer-set-expression
|
// >> timer-set-expression
|
||||||
const id = timer.setInterval(() => {
|
const id = timer.setInterval(() => {
|
||||||
// >> (hide)
|
// >> (hide)
|
||||||
counter++;
|
counter++;
|
||||||
if (counter === 4) {
|
if (counter === expected) {
|
||||||
const end = TKUnit.time();
|
const end = TKUnit.time();
|
||||||
timer.clearInterval(id);
|
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)
|
// << (hide)
|
||||||
}, 50);
|
}, 50);
|
||||||
|
Reference in New Issue
Block a user