summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2021-02-04 11:54:09 -0800
committerRich Trott <rtrott@gmail.com>2021-02-13 06:06:32 -0800
commitb4264b53b66de274de0ca8d2d91fe9563799f930 (patch)
treeb63775f42bd4003d17797501ae94ed86b5b63c15
parent88d9268d087eea0d5cd6e7b731b3679c266fb74f (diff)
downloadnode-new-b4264b53b66de274de0ca8d2d91fe9563799f930.tar.gz
test: re-implement promises.setInterval() test robustly
Fixes: https://github.com/nodejs/node/issues/37226 PR-URL: https://github.com/nodejs/node/pull/37230 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
-rw-r--r--test/parallel/test-timers-promisified.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/parallel/test-timers-promisified.js b/test/parallel/test-timers-promisified.js
index 348f6c2ae0..3e68470c7d 100644
--- a/test/parallel/test-timers-promisified.js
+++ b/test/parallel/test-timers-promisified.js
@@ -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`);
+ }));
+ }
}
{