From 24e81d7c5ae785a015ac56ad75fe83120a998a3a Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Sat, 25 Jan 2020 12:01:30 +0100 Subject: [PATCH] stream: add regression test for async iteration completion A test was missing for an async iterator created after the stream had emitted 'close'. This was regressed by #31314. See: https://github.com/nodejs/node/pull/31314 PR-URL: https://github.com/nodejs/node/pull/31508 Reviewed-By: James M Snell Reviewed-By: Anatoli Papirovski Reviewed-By: Colin Ihrig Reviewed-By: Rich Trott Reviewed-By: Benjamin Gruenbaum --- .../test-stream-readable-async-iterators.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/parallel/test-stream-readable-async-iterators.js b/test/parallel/test-stream-readable-async-iterators.js index 58f33177aa92cf..eb8aa0b34f20fe 100644 --- a/test/parallel/test-stream-readable-async-iterators.js +++ b/test/parallel/test-stream-readable-async-iterators.js @@ -610,5 +610,24 @@ async function tests() { p.then(common.mustCall()).catch(common.mustNotCall()); } +{ + // AsyncIterator should finish correctly if destroyed. + + const r = new Readable({ + objectMode: true, + read() { + } + }); + + r.destroy(); + r.on('close', () => { + const it = r[Symbol.asyncIterator](); + const next = it.next(); + next + .then(common.mustCall(({ done }) => assert.strictEqual(done, true))) + .catch(common.mustNotCall()); + }); +} + // To avoid missing some tests if a promise does not resolve tests().then(common.mustCall());