11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst { 51cb0ef41Sopenharmony_ci Writable, 61cb0ef41Sopenharmony_ci Readable, 71cb0ef41Sopenharmony_ci destroy 81cb0ef41Sopenharmony_ci} = require('stream'); 91cb0ef41Sopenharmony_ciconst assert = require('assert'); 101cb0ef41Sopenharmony_ciconst http = require('http'); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci{ 131cb0ef41Sopenharmony_ci const r = new Readable({ read() {} }); 141cb0ef41Sopenharmony_ci destroy(r); 151cb0ef41Sopenharmony_ci assert.strictEqual(r.destroyed, true); 161cb0ef41Sopenharmony_ci r.on('error', common.mustCall((err) => { 171cb0ef41Sopenharmony_ci assert.strictEqual(err.name, 'AbortError'); 181cb0ef41Sopenharmony_ci })); 191cb0ef41Sopenharmony_ci r.on('close', common.mustCall()); 201cb0ef41Sopenharmony_ci} 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci{ 231cb0ef41Sopenharmony_ci const r = new Readable({ read() {} }); 241cb0ef41Sopenharmony_ci destroy(r, new Error('asd')); 251cb0ef41Sopenharmony_ci assert.strictEqual(r.destroyed, true); 261cb0ef41Sopenharmony_ci r.on('error', common.mustCall((err) => { 271cb0ef41Sopenharmony_ci assert.strictEqual(err.message, 'asd'); 281cb0ef41Sopenharmony_ci })); 291cb0ef41Sopenharmony_ci r.on('close', common.mustCall()); 301cb0ef41Sopenharmony_ci} 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci{ 331cb0ef41Sopenharmony_ci const w = new Writable({ write() {} }); 341cb0ef41Sopenharmony_ci destroy(w); 351cb0ef41Sopenharmony_ci assert.strictEqual(w.destroyed, true); 361cb0ef41Sopenharmony_ci w.on('error', common.mustCall((err) => { 371cb0ef41Sopenharmony_ci assert.strictEqual(err.name, 'AbortError'); 381cb0ef41Sopenharmony_ci })); 391cb0ef41Sopenharmony_ci w.on('close', common.mustCall()); 401cb0ef41Sopenharmony_ci} 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ci{ 431cb0ef41Sopenharmony_ci const w = new Writable({ write() {} }); 441cb0ef41Sopenharmony_ci destroy(w, new Error('asd')); 451cb0ef41Sopenharmony_ci assert.strictEqual(w.destroyed, true); 461cb0ef41Sopenharmony_ci w.on('error', common.mustCall((err) => { 471cb0ef41Sopenharmony_ci assert.strictEqual(err.message, 'asd'); 481cb0ef41Sopenharmony_ci })); 491cb0ef41Sopenharmony_ci w.on('close', common.mustCall()); 501cb0ef41Sopenharmony_ci} 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ci{ 531cb0ef41Sopenharmony_ci const server = http.createServer((req, res) => { 541cb0ef41Sopenharmony_ci destroy(req); 551cb0ef41Sopenharmony_ci req.on('error', common.mustCall((err) => { 561cb0ef41Sopenharmony_ci assert.strictEqual(err.name, 'AbortError'); 571cb0ef41Sopenharmony_ci })); 581cb0ef41Sopenharmony_ci req.on('close', common.mustCall(() => { 591cb0ef41Sopenharmony_ci res.end('hello'); 601cb0ef41Sopenharmony_ci })); 611cb0ef41Sopenharmony_ci }); 621cb0ef41Sopenharmony_ci 631cb0ef41Sopenharmony_ci server.listen(0, () => { 641cb0ef41Sopenharmony_ci const req = http.request({ 651cb0ef41Sopenharmony_ci port: server.address().port 661cb0ef41Sopenharmony_ci }); 671cb0ef41Sopenharmony_ci 681cb0ef41Sopenharmony_ci req.write('asd'); 691cb0ef41Sopenharmony_ci req.on('response', (res) => { 701cb0ef41Sopenharmony_ci const buf = []; 711cb0ef41Sopenharmony_ci res.on('data', (data) => buf.push(data)); 721cb0ef41Sopenharmony_ci res.on('end', common.mustCall(() => { 731cb0ef41Sopenharmony_ci assert.deepStrictEqual( 741cb0ef41Sopenharmony_ci Buffer.concat(buf), 751cb0ef41Sopenharmony_ci Buffer.from('hello') 761cb0ef41Sopenharmony_ci ); 771cb0ef41Sopenharmony_ci server.close(); 781cb0ef41Sopenharmony_ci })); 791cb0ef41Sopenharmony_ci }); 801cb0ef41Sopenharmony_ci }); 811cb0ef41Sopenharmony_ci} 821cb0ef41Sopenharmony_ci 831cb0ef41Sopenharmony_ci{ 841cb0ef41Sopenharmony_ci const server = http.createServer((req, res) => { 851cb0ef41Sopenharmony_ci req 861cb0ef41Sopenharmony_ci .resume() 871cb0ef41Sopenharmony_ci .on('end', () => { 881cb0ef41Sopenharmony_ci destroy(req); 891cb0ef41Sopenharmony_ci }) 901cb0ef41Sopenharmony_ci .on('error', common.mustNotCall()); 911cb0ef41Sopenharmony_ci 921cb0ef41Sopenharmony_ci req.on('close', common.mustCall(() => { 931cb0ef41Sopenharmony_ci res.end('hello'); 941cb0ef41Sopenharmony_ci })); 951cb0ef41Sopenharmony_ci }); 961cb0ef41Sopenharmony_ci 971cb0ef41Sopenharmony_ci server.listen(0, () => { 981cb0ef41Sopenharmony_ci const req = http.request({ 991cb0ef41Sopenharmony_ci port: server.address().port 1001cb0ef41Sopenharmony_ci }); 1011cb0ef41Sopenharmony_ci 1021cb0ef41Sopenharmony_ci req.write('asd'); 1031cb0ef41Sopenharmony_ci req.on('response', (res) => { 1041cb0ef41Sopenharmony_ci const buf = []; 1051cb0ef41Sopenharmony_ci res.on('data', (data) => buf.push(data)); 1061cb0ef41Sopenharmony_ci res.on('end', common.mustCall(() => { 1071cb0ef41Sopenharmony_ci assert.deepStrictEqual( 1081cb0ef41Sopenharmony_ci Buffer.concat(buf), 1091cb0ef41Sopenharmony_ci Buffer.from('hello') 1101cb0ef41Sopenharmony_ci ); 1111cb0ef41Sopenharmony_ci server.close(); 1121cb0ef41Sopenharmony_ci })); 1131cb0ef41Sopenharmony_ci }); 1141cb0ef41Sopenharmony_ci }); 1151cb0ef41Sopenharmony_ci} 116