mirror of
https://github.com/denoland/deno.git
synced 2025-02-15 18:16:12 -05:00
chore(tests): update flaky timer test (#22701)
This test was flaky after landing the new timer rewrite.
This commit is contained in:
parent
064d9121ff
commit
613936c7c7
1 changed files with 19 additions and 13 deletions
|
@ -228,24 +228,30 @@ Deno.test(function intervalCancelInvalidSilentFail() {
|
||||||
clearInterval(2147483647);
|
clearInterval(2147483647);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// If a repeating timer is dispatched, the next interval that should first is based on
|
||||||
|
// when the timer is dispatched, not when the timer handler completes.
|
||||||
Deno.test(async function callbackTakesLongerThanInterval() {
|
Deno.test(async function callbackTakesLongerThanInterval() {
|
||||||
const { promise, resolve } = Promise.withResolvers<void>();
|
const { promise, resolve } = Promise.withResolvers<void>();
|
||||||
|
const output: number[] = [];
|
||||||
let timeEndOfFirstCallback: number | undefined;
|
let last = 0;
|
||||||
const interval = setInterval(() => {
|
const id = setInterval(() => {
|
||||||
if (timeEndOfFirstCallback === undefined) {
|
const now = performance.now();
|
||||||
// First callback
|
if (last > 0) {
|
||||||
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 300);
|
output.push(now - last);
|
||||||
timeEndOfFirstCallback = Date.now();
|
if (output.length >= 10) {
|
||||||
} else {
|
resolve();
|
||||||
// Second callback should be nearly instantaneous
|
clearTimeout(id);
|
||||||
assert(Date.now() - timeEndOfFirstCallback < 10);
|
}
|
||||||
clearInterval(interval);
|
}
|
||||||
resolve();
|
last = now;
|
||||||
|
while (performance.now() - now < 300) {
|
||||||
|
/* hot loop */
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
await promise;
|
await promise;
|
||||||
|
const total = output.reduce((t, n) => t + n, 0) / output.length;
|
||||||
|
console.log(output);
|
||||||
|
assert(total < 350 && total > 299, "Total was out of range: " + total);
|
||||||
});
|
});
|
||||||
|
|
||||||
// https://github.com/denoland/deno/issues/11398
|
// https://github.com/denoland/deno/issues/11398
|
||||||
|
|
Loading…
Add table
Reference in a new issue