11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci// This test ensures that Readable stream will call _read() for streams 61cb0ef41Sopenharmony_ci// with highWaterMark === 0 upon .read(0) instead of just trying to 71cb0ef41Sopenharmony_ci// emit 'readable' event. 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst assert = require('assert'); 101cb0ef41Sopenharmony_ciconst { Readable } = require('stream'); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciconst r = new Readable({ 131cb0ef41Sopenharmony_ci // Must be called only once upon setting 'readable' listener 141cb0ef41Sopenharmony_ci read: common.mustCall(), 151cb0ef41Sopenharmony_ci highWaterMark: 0, 161cb0ef41Sopenharmony_ci}); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_cilet pushedNull = false; 191cb0ef41Sopenharmony_ci// This will trigger read(0) but must only be called after push(null) 201cb0ef41Sopenharmony_ci// because the we haven't pushed any data 211cb0ef41Sopenharmony_cir.on('readable', common.mustCall(() => { 221cb0ef41Sopenharmony_ci assert.strictEqual(r.read(), null); 231cb0ef41Sopenharmony_ci assert.strictEqual(pushedNull, true); 241cb0ef41Sopenharmony_ci})); 251cb0ef41Sopenharmony_cir.on('end', common.mustCall()); 261cb0ef41Sopenharmony_ciprocess.nextTick(() => { 271cb0ef41Sopenharmony_ci assert.strictEqual(r.read(), null); 281cb0ef41Sopenharmony_ci pushedNull = true; 291cb0ef41Sopenharmony_ci r.push(null); 301cb0ef41Sopenharmony_ci}); 31