Skip to content

Commit

Permalink
test: re-implement promises.setInterval() test robustly
Browse files Browse the repository at this point in the history
Fixes: #37226

PR-URL: #37230
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
Trott authored and danielleadams committed Feb 16, 2021
1 parent 15804e0 commit 1fc8307
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/parallel/test-timers-promisified.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,34 @@ process.on('multipleResolves', common.mustNotCall());
assert.strictEqual(loopCount, 5);
}));
}

{
// Check that if we abort when we have some unresolved callbacks,
// we actually call them.
const controller = new AbortController();
const { signal } = controller;
const delay = 10;
let totalIterations = 0;
const timeoutLoop = runInterval(async (iterationNumber) => {
await setTimeout(delay * 4);
if (iterationNumber <= 2) {
assert.strictEqual(signal.aborted, false);
}
if (iterationNumber === 2) {
controller.abort();
}
if (iterationNumber > 2) {
assert.strictEqual(signal.aborted, true);
}
if (iterationNumber > totalIterations) {
totalIterations = iterationNumber;
}
}, delay, signal);

timeoutLoop.catch(common.mustCall(() => {
assert.ok(totalIterations >= 3, `iterations was ${totalIterations} < 3`);
}));
}
}

{
Expand Down

0 comments on commit 1fc8307

Please sign in to comment.