fix(web): unit-test workaround for node setTimeout 1ms-early bug

This commit is contained in:
Joshua A. Horton 2023-07-18 09:48:21 +07:00
parent b9c746b522
commit 0c7340129a

View file

@ -14,6 +14,7 @@ describe("TimeoutPromise", () => {
assert.isTrue(await promise.corePromise);
const end = Date.now();
// https://github.com/nodejs/node/issues/26578 - setTimeout() may resolve 1ms early than requested.
assert.isAtLeast(end-start, INTERVAL);
});
@ -59,7 +60,8 @@ describe("TimeoutPromise", () => {
const end = Date.now();
assert.isAtMost(end-start, INTERVAL-1); // completes early
assert.isAtLeast(end-start, INTERVAL/2); // but not TOO early
// https://github.com/nodejs/node/issues/26578 - setTimeout() may resolve 1ms early than requested.
assert.isAtLeast(end-start, INTERVAL/2-1); // but not TOO early
});
it('late dual fulfillment does not change first result', async () => {
@ -69,6 +71,7 @@ describe("TimeoutPromise", () => {
assert.isTrue(await promise.corePromise);
const end = Date.now();
// https://github.com/nodejs/node/issues/26578 - setTimeout() may resolve 1ms early than requested.
assert.isAtLeast(end-start, INTERVAL);
promise.resolve(false);