1'use strict'; 2 3// This test ensures that the _writeableState.bufferedRequestCount and 4// the actual buffered request count are the same. 5 6const common = require('../common'); 7const Stream = require('stream'); 8const assert = require('assert'); 9 10class StreamWritable extends Stream.Writable { 11 constructor() { 12 super({ objectMode: true }); 13 } 14 15 // Refs: https://github.com/nodejs/node/issues/6758 16 // We need a timer like on the original issue thread. 17 // Otherwise the code will never reach our test case. 18 _write(chunk, encoding, cb) { 19 setImmediate(cb); 20 } 21} 22 23const testStream = new StreamWritable(); 24testStream.cork(); 25 26for (let i = 1; i <= 5; i++) { 27 testStream.write(i, common.mustCall(() => { 28 assert.strictEqual( 29 testStream._writableState.bufferedRequestCount, 30 testStream._writableState.getBuffer().length 31 ); 32 })); 33} 34 35testStream.end(); 36