11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst { Writable, Readable } = require('stream');
51cb0ef41Sopenharmony_ciclass NullWriteable extends Writable {
61cb0ef41Sopenharmony_ci  _write(chunk, encoding, callback) {
71cb0ef41Sopenharmony_ci    return callback();
81cb0ef41Sopenharmony_ci  }
91cb0ef41Sopenharmony_ci}
101cb0ef41Sopenharmony_ciclass QuickEndReadable extends Readable {
111cb0ef41Sopenharmony_ci  _read() {
121cb0ef41Sopenharmony_ci    this.push(null);
131cb0ef41Sopenharmony_ci  }
141cb0ef41Sopenharmony_ci}
151cb0ef41Sopenharmony_ciclass NeverEndReadable extends Readable {
161cb0ef41Sopenharmony_ci  _read() {}
171cb0ef41Sopenharmony_ci}
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci{
201cb0ef41Sopenharmony_ci  const dest = new NullWriteable();
211cb0ef41Sopenharmony_ci  const src = new QuickEndReadable();
221cb0ef41Sopenharmony_ci  dest.on('pipe', common.mustCall());
231cb0ef41Sopenharmony_ci  dest.on('unpipe', common.mustCall());
241cb0ef41Sopenharmony_ci  src.pipe(dest);
251cb0ef41Sopenharmony_ci  setImmediate(() => {
261cb0ef41Sopenharmony_ci    assert.strictEqual(src._readableState.pipes.length, 0);
271cb0ef41Sopenharmony_ci  });
281cb0ef41Sopenharmony_ci}
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci{
311cb0ef41Sopenharmony_ci  const dest = new NullWriteable();
321cb0ef41Sopenharmony_ci  const src = new NeverEndReadable();
331cb0ef41Sopenharmony_ci  dest.on('pipe', common.mustCall());
341cb0ef41Sopenharmony_ci  dest.on('unpipe', common.mustNotCall('unpipe should not have been emitted'));
351cb0ef41Sopenharmony_ci  src.pipe(dest);
361cb0ef41Sopenharmony_ci  setImmediate(() => {
371cb0ef41Sopenharmony_ci    assert.strictEqual(src._readableState.pipes.length, 1);
381cb0ef41Sopenharmony_ci  });
391cb0ef41Sopenharmony_ci}
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci{
421cb0ef41Sopenharmony_ci  const dest = new NullWriteable();
431cb0ef41Sopenharmony_ci  const src = new NeverEndReadable();
441cb0ef41Sopenharmony_ci  dest.on('pipe', common.mustCall());
451cb0ef41Sopenharmony_ci  dest.on('unpipe', common.mustCall());
461cb0ef41Sopenharmony_ci  src.pipe(dest);
471cb0ef41Sopenharmony_ci  src.unpipe(dest);
481cb0ef41Sopenharmony_ci  setImmediate(() => {
491cb0ef41Sopenharmony_ci    assert.strictEqual(src._readableState.pipes.length, 0);
501cb0ef41Sopenharmony_ci  });
511cb0ef41Sopenharmony_ci}
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ci{
541cb0ef41Sopenharmony_ci  const dest = new NullWriteable();
551cb0ef41Sopenharmony_ci  const src = new QuickEndReadable();
561cb0ef41Sopenharmony_ci  dest.on('pipe', common.mustCall());
571cb0ef41Sopenharmony_ci  dest.on('unpipe', common.mustCall());
581cb0ef41Sopenharmony_ci  src.pipe(dest, { end: false });
591cb0ef41Sopenharmony_ci  setImmediate(() => {
601cb0ef41Sopenharmony_ci    assert.strictEqual(src._readableState.pipes.length, 0);
611cb0ef41Sopenharmony_ci  });
621cb0ef41Sopenharmony_ci}
631cb0ef41Sopenharmony_ci
641cb0ef41Sopenharmony_ci{
651cb0ef41Sopenharmony_ci  const dest = new NullWriteable();
661cb0ef41Sopenharmony_ci  const src = new NeverEndReadable();
671cb0ef41Sopenharmony_ci  dest.on('pipe', common.mustCall());
681cb0ef41Sopenharmony_ci  dest.on('unpipe', common.mustNotCall('unpipe should not have been emitted'));
691cb0ef41Sopenharmony_ci  src.pipe(dest, { end: false });
701cb0ef41Sopenharmony_ci  setImmediate(() => {
711cb0ef41Sopenharmony_ci    assert.strictEqual(src._readableState.pipes.length, 1);
721cb0ef41Sopenharmony_ci  });
731cb0ef41Sopenharmony_ci}
741cb0ef41Sopenharmony_ci
751cb0ef41Sopenharmony_ci{
761cb0ef41Sopenharmony_ci  const dest = new NullWriteable();
771cb0ef41Sopenharmony_ci  const src = new NeverEndReadable();
781cb0ef41Sopenharmony_ci  dest.on('pipe', common.mustCall());
791cb0ef41Sopenharmony_ci  dest.on('unpipe', common.mustCall());
801cb0ef41Sopenharmony_ci  src.pipe(dest, { end: false });
811cb0ef41Sopenharmony_ci  src.unpipe(dest);
821cb0ef41Sopenharmony_ci  setImmediate(() => {
831cb0ef41Sopenharmony_ci    assert.strictEqual(src._readableState.pipes.length, 0);
841cb0ef41Sopenharmony_ci  });
851cb0ef41Sopenharmony_ci}
86