mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
fix(test): Make the op sanitizer delay macrotask into a queue (#12966)
Fixes #12945.
This commit is contained in:
parent
cbfc8dd59d
commit
a3aa2c184c
1 changed files with 6 additions and 12 deletions
|
@ -12,6 +12,7 @@
|
|||
AggregateError,
|
||||
ArrayPrototypeFilter,
|
||||
ArrayPrototypePush,
|
||||
ArrayPrototypeShift,
|
||||
ArrayPrototypeSome,
|
||||
DateNow,
|
||||
Error,
|
||||
|
@ -30,7 +31,7 @@
|
|||
} = window.__bootstrap.primordials;
|
||||
let testStepsEnabled = false;
|
||||
|
||||
let opSanitizerDelayResolve = null;
|
||||
const opSanitizerDelayResolveQueue = [];
|
||||
|
||||
// Even if every resource is closed by the end of a test, there can be a delay
|
||||
// until the pending ops have all finished. This function returns a promise
|
||||
|
@ -42,23 +43,16 @@
|
|||
// before that, though, in order to give time for worker message ops to finish
|
||||
// (since timeouts of 0 don't queue tasks in the timer queue immediately).
|
||||
function opSanitizerDelay() {
|
||||
return new Promise((resolve, reject) => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
if (opSanitizerDelayResolve !== null) {
|
||||
reject(new Error("There is an op sanitizer delay already."));
|
||||
} else {
|
||||
opSanitizerDelayResolve = resolve;
|
||||
}
|
||||
ArrayPrototypePush(opSanitizerDelayResolveQueue, resolve);
|
||||
}, 0);
|
||||
});
|
||||
}
|
||||
|
||||
function handleOpSanitizerDelayMacrotask() {
|
||||
if (opSanitizerDelayResolve !== null) {
|
||||
opSanitizerDelayResolve();
|
||||
opSanitizerDelayResolve = null;
|
||||
}
|
||||
return true;
|
||||
ArrayPrototypeShift(opSanitizerDelayResolveQueue)?.();
|
||||
return opSanitizerDelayResolveQueue.length === 0;
|
||||
}
|
||||
|
||||
// Wrap test function in additional assertion that makes sure
|
||||
|
|
Loading…
Reference in a new issue