Skip to content

Commit

Permalink
test: add abort test case and check either entire event map or abort …
Browse files Browse the repository at this point in the history
…listener list
  • Loading branch information
nbbeeken committed Mar 14, 2024
1 parent f8e9b45 commit 01aade6
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions test/parallel/test-events-on-async-iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 01aade6

Please sign in to comment.