11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst { Readable, Writable } = require('stream'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci// Tests that calling .unpipe() un-blocks a stream that is paused because 61cb0ef41Sopenharmony_ci// it is waiting on the writable side to finish a write(). 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst rs = new Readable({ 91cb0ef41Sopenharmony_ci highWaterMark: 1, 101cb0ef41Sopenharmony_ci // That this gets called at least 20 times is the real test here. 111cb0ef41Sopenharmony_ci read: common.mustCallAtLeast(() => rs.push('foo'), 20) 121cb0ef41Sopenharmony_ci}); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ciconst ws = new Writable({ 151cb0ef41Sopenharmony_ci highWaterMark: 1, 161cb0ef41Sopenharmony_ci write: common.mustCall(() => { 171cb0ef41Sopenharmony_ci // Ignore the callback, this write() simply never finishes. 181cb0ef41Sopenharmony_ci setImmediate(() => rs.unpipe(ws)); 191cb0ef41Sopenharmony_ci }) 201cb0ef41Sopenharmony_ci}); 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_cilet chunks = 0; 231cb0ef41Sopenharmony_cirs.on('data', common.mustCallAtLeast(() => { 241cb0ef41Sopenharmony_ci chunks++; 251cb0ef41Sopenharmony_ci if (chunks >= 20) 261cb0ef41Sopenharmony_ci rs.pause(); // Finish this test. 271cb0ef41Sopenharmony_ci})); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_cirs.pipe(ws); 30