Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMatteo Collina <hello@matteocollina.com>2018-10-20 16:04:57 +0300
committerMyles Borins <mylesborins@google.com>2018-11-29 19:39:12 +0300
commitce79ae6544fdeb86092148065970fad5270d74c0 (patch)
tree635adb74317686fe068773e39ac756a553ab1eea /test
parent7a39fec1db3292884b6e8bf080573744e5de9593 (diff)
stream: async iteration should work with destroyed stream
Fixes https://github.com/nodejs/node/issues/23730. PR-URL: https://github.com/nodejs/node/pull/23785 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matheus Marchini <mat@mmarchini.me>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-stream-readable-async-iterators.js40
1 files changed, 39 insertions, 1 deletions
diff --git a/test/parallel/test-stream-readable-async-iterators.js b/test/parallel/test-stream-readable-async-iterators.js
index fb3c55846c4..ec558955c6e 100644
--- a/test/parallel/test-stream-readable-async-iterators.js
+++ b/test/parallel/test-stream-readable-async-iterators.js
@@ -1,7 +1,7 @@
'use strict';
const common = require('../common');
-const { Readable } = require('stream');
+const { Readable, PassThrough, pipeline } = require('stream');
const assert = require('assert');
async function tests() {
@@ -324,6 +324,44 @@ async function tests() {
assert.strictEqual(data, expected);
})();
+
+ await (async function() {
+ console.log('.next() on destroyed stream');
+ const readable = new Readable({
+ read() {
+ // no-op
+ }
+ });
+
+ readable.destroy();
+
+ try {
+ await readable[Symbol.asyncIterator]().next();
+ } catch (e) {
+ assert.strictEqual(e.code, 'ERR_STREAM_PREMATURE_CLOSE');
+ }
+ })();
+
+ await (async function() {
+ console.log('.next() on pipelined stream');
+ const readable = new Readable({
+ read() {
+ // no-op
+ }
+ });
+
+ const passthrough = new PassThrough();
+ const err = new Error('kaboom');
+ pipeline(readable, passthrough, common.mustCall((e) => {
+ assert.strictEqual(e, err);
+ }));
+ readable.destroy(err);
+ try {
+ await readable[Symbol.asyncIterator]().next();
+ } catch (e) {
+ assert.strictEqual(e, err);
+ }
+ })();
}
// to avoid missing some tests if a promise does not resolve