From 719f745c5f617869076a51691c12372a8ec73f42 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Thu, 14 Mar 2024 10:00:41 -0400 Subject: [PATCH] test: add abort test case and check either entire event map or abort listener list --- test/parallel/test-events-on-async-iterator.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-events-on-async-iterator.js b/test/parallel/test-events-on-async-iterator.js index fd31d1a33af6ab..2a68bf987dde28 100644 --- a/test/parallel/test-events-on-async-iterator.js +++ b/test/parallel/test-events-on-async-iterator.js @@ -379,17 +379,25 @@ async function abortListenerRemovedAfterComplete() { const i = setInterval(() => ee.emit('foo', 'foo'), 1); try { + // Below: either the kEvents map is empty or the 'abort' listener list is empty + // Return case const endedIterator = on(ee, 'foo', { signal: ac.signal }); - assert.ok(ac.signal[kEvents].size > 0); + assert.ok(ac.signal[kEvents].get('abort').size > 0); endedIterator.return(); - assert.strictEqual(ac.signal[kEvents].size, 0); + assert.strictEqual(ac.signal[kEvents].get('abort')?.size ?? ac.signal[kEvents].size, 0); // Throw case const throwIterator = on(ee, 'foo', { signal: ac.signal }); - assert.ok(ac.signal[kEvents].size > 0); + assert.ok(ac.signal[kEvents].get('abort').size > 0); throwIterator.throw(new Error()); - assert.strictEqual(ac.signal[kEvents].size, 0); + assert.strictEqual(ac.signal[kEvents].get('abort')?.size ?? ac.signal[kEvents].size, 0); + + // Abort case + on(ee, 'foo', { signal: ac.signal }); + assert.ok(ac.signal[kEvents].get('abort').size > 0); + ac.abort(new Error()); + assert.strictEqual(ac.signal[kEvents].get('abort')?.size ?? ac.signal[kEvents].size, 0); } finally { clearInterval(i); }