11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// This test ensures that the _writeableState.bufferedRequestCount and 41cb0ef41Sopenharmony_ci// the actual buffered request count are the same. 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst common = require('../common'); 71cb0ef41Sopenharmony_ciconst Stream = require('stream'); 81cb0ef41Sopenharmony_ciconst assert = require('assert'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciclass StreamWritable extends Stream.Writable { 111cb0ef41Sopenharmony_ci constructor() { 121cb0ef41Sopenharmony_ci super({ objectMode: true }); 131cb0ef41Sopenharmony_ci } 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci // Refs: https://github.com/nodejs/node/issues/6758 161cb0ef41Sopenharmony_ci // We need a timer like on the original issue thread. 171cb0ef41Sopenharmony_ci // Otherwise the code will never reach our test case. 181cb0ef41Sopenharmony_ci _write(chunk, encoding, cb) { 191cb0ef41Sopenharmony_ci setImmediate(cb); 201cb0ef41Sopenharmony_ci } 211cb0ef41Sopenharmony_ci} 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ciconst testStream = new StreamWritable(); 241cb0ef41Sopenharmony_citestStream.cork(); 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_cifor (let i = 1; i <= 5; i++) { 271cb0ef41Sopenharmony_ci testStream.write(i, common.mustCall(() => { 281cb0ef41Sopenharmony_ci assert.strictEqual( 291cb0ef41Sopenharmony_ci testStream._writableState.bufferedRequestCount, 301cb0ef41Sopenharmony_ci testStream._writableState.getBuffer().length 311cb0ef41Sopenharmony_ci ); 321cb0ef41Sopenharmony_ci })); 331cb0ef41Sopenharmony_ci} 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_citestStream.end(); 36