summaryrefslogtreecommitdiff
path: root/test/parallel/test-stream-destroy.js
diff options
context:
space:
mode:
authorRobert Nagy <ronagy@icloud.com>2021-05-02 18:17:18 +0200
committerDaniele Belardi <dwon.dnl@gmail.com>2021-06-15 19:43:49 +0200
commitf4609bdf3fabdf441da6af17c2022565f4e18f9d (patch)
tree82bc067adc7902be0b866abbb85ff7c4ae547f65 /test/parallel/test-stream-destroy.js
parentc0becbc1bdebf0038dbf6683e347db09011d3004 (diff)
downloadnode-new-f4609bdf3fabdf441da6af17c2022565f4e18f9d.tar.gz
stream: bypass legacy destroy for pipeline and async iteration
PR-URL: https://github.com/nodejs/node/pull/38505 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-stream-destroy.js')
-rw-r--r--test/parallel/test-stream-destroy.js115
1 files changed, 115 insertions, 0 deletions
diff --git a/test/parallel/test-stream-destroy.js b/test/parallel/test-stream-destroy.js
new file mode 100644
index 0000000000..f99c29c811
--- /dev/null
+++ b/test/parallel/test-stream-destroy.js
@@ -0,0 +1,115 @@
+'use strict';
+
+const common = require('../common');
+const {
+ Writable,
+ Readable,
+ destroy
+} = require('stream');
+const assert = require('assert');
+const http = require('http');
+
+{
+ const r = new Readable({ read() {} });
+ destroy(r);
+ assert.strictEqual(r.destroyed, true);
+ r.on('error', common.mustCall((err) => {
+ assert.strictEqual(err.name, 'AbortError');
+ }));
+ r.on('close', common.mustCall());
+}
+
+{
+ const r = new Readable({ read() {} });
+ destroy(r, new Error('asd'));
+ assert.strictEqual(r.destroyed, true);
+ r.on('error', common.mustCall((err) => {
+ assert.strictEqual(err.message, 'asd');
+ }));
+ r.on('close', common.mustCall());
+}
+
+{
+ const w = new Writable({ write() {} });
+ destroy(w);
+ assert.strictEqual(w.destroyed, true);
+ w.on('error', common.mustCall((err) => {
+ assert.strictEqual(err.name, 'AbortError');
+ }));
+ w.on('close', common.mustCall());
+}
+
+{
+ const w = new Writable({ write() {} });
+ destroy(w, new Error('asd'));
+ assert.strictEqual(w.destroyed, true);
+ w.on('error', common.mustCall((err) => {
+ assert.strictEqual(err.message, 'asd');
+ }));
+ w.on('close', common.mustCall());
+}
+
+{
+ const server = http.createServer((req, res) => {
+ destroy(req);
+ req.on('error', common.mustCall((err) => {
+ assert.strictEqual(err.name, 'AbortError');
+ }));
+ req.on('close', common.mustCall(() => {
+ res.end('hello');
+ }));
+ });
+
+ server.listen(0, () => {
+ const req = http.request({
+ port: server.address().port
+ });
+
+ req.write('asd');
+ req.on('response', (res) => {
+ const buf = [];
+ res.on('data', (data) => buf.push(data));
+ res.on('end', common.mustCall(() => {
+ assert.deepStrictEqual(
+ Buffer.concat(buf),
+ Buffer.from('hello')
+ );
+ server.close();
+ }));
+ });
+ });
+}
+
+{
+ const server = http.createServer((req, res) => {
+ req
+ .resume()
+ .on('end', () => {
+ destroy(req);
+ })
+ .on('error', common.mustNotCall());
+
+ req.on('close', common.mustCall(() => {
+ res.end('hello');
+ }));
+ });
+
+ server.listen(0, () => {
+ const req = http.request({
+ port: server.address().port
+ });
+
+ req.write('asd');
+ req.on('response', (res) => {
+ const buf = [];
+ res.on('data', (data) => buf.push(data));
+ res.on('end', common.mustCall(() => {
+ assert.deepStrictEqual(
+ Buffer.concat(buf),
+ Buffer.from('hello')
+ );
+ server.close();
+ }));
+ });
+ });
+}