Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1fc8307

Browse filesBrowse files
Trottdanielleadams
authored andcommitted
test: re-implement promises.setInterval() test robustly
Fixes: #37226 PR-URL: #37230 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 15804e0 commit 1fc8307
Copy full SHA for 1fc8307

File tree

Expand file treeCollapse file tree

1 file changed

+28
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+28
-0
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-timers-promisified.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-timers-promisified.js
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,34 @@ process.on('multipleResolves', common.mustNotCall());
348348
assert.strictEqual(loopCount, 5);
349349
}));
350350
}
351+
352+
{
353+
// Check that if we abort when we have some unresolved callbacks,
354+
// we actually call them.
355+
const controller = new AbortController();
356+
const { signal } = controller;
357+
const delay = 10;
358+
let totalIterations = 0;
359+
const timeoutLoop = runInterval(async (iterationNumber) => {
360+
await setTimeout(delay * 4);
361+
if (iterationNumber <= 2) {
362+
assert.strictEqual(signal.aborted, false);
363+
}
364+
if (iterationNumber === 2) {
365+
controller.abort();
366+
}
367+
if (iterationNumber > 2) {
368+
assert.strictEqual(signal.aborted, true);
369+
}
370+
if (iterationNumber > totalIterations) {
371+
totalIterations = iterationNumber;
372+
}
373+
}, delay, signal);
374+
375+
timeoutLoop.catch(common.mustCall(() => {
376+
assert.ok(totalIterations >= 3, `iterations was ${totalIterations} < 3`);
377+
}));
378+
}
351379
}
352380

353381
{

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.