1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

fix(test): Make the op sanitizer delay macrotask into a queue (#12966)

Fixes #12945.
This commit is contained in:
Andreu Botella 2021-12-11 00:30:46 +01:00 committed by GitHub
parent cbfc8dd59d
commit a3aa2c184c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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