From d676d1de763d7e3ec8502450be4c5e9ccb60ceba Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 6 Feb 2021 04:56:50 -0800 Subject: [PATCH] fixup! test: re-implement promises.setInterval() test robustly --- test/parallel/test-timers-promisified.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/test/parallel/test-timers-promisified.js b/test/parallel/test-timers-promisified.js index b9d971b3f2ab52..cb0c14c130ef9f 100644 --- a/test/parallel/test-timers-promisified.js +++ b/test/parallel/test-timers-promisified.js @@ -321,11 +321,14 @@ process.on('multipleResolves', common.mustNotCall()); } { - async function runInterval(fn, intervalTime, signal) { + async function runInterval(fn, intervalTime, signal, emitter) { const input = 'foobar'; const interval = setInterval(intervalTime, input, { signal }); let iteration = 0; for await (const value of interval) { + if (emitter) { + emitter.emit('myevent'); + } assert.strictEqual(value, input); iteration++; await fn(iteration); @@ -359,18 +362,21 @@ process.on('multipleResolves', common.mustNotCall()); const delay = 10; let totalIterations = 0; const timeoutLoop = runInterval(async (iterationNumber) => { - myEvent.emit('myevent'); - // The call to abort() will typically happen while we're awaiting here. - await setTimeout(delay); + if (iterationNumber <= 2) { + assert.strictEqual(signal.aborted, false); + } if (iterationNumber === 2) { myEvent.once('myevent', () => { controller.abort(); }); } + if (iterationNumber > 2) { + assert.strictEqual(signal.aborted, true); + } if (iterationNumber > totalIterations) { totalIterations = iterationNumber; } - }, delay, signal); + }, delay, signal, myEvent); timeoutLoop.catch(common.mustCall(() => { assert.ok(totalIterations >= 3, `iterations was ${totalIterations} < 3`);