-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream: fix disparity between buffer and the count
This changes the disparity of bufferedRequestCount and the actual buffer on file _stream_writable.js PR-URL: #15661 Fixes: #6758 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
1 parent
7842f63
commit ae91ffe
Showing
2 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const Stream = require('stream'); | ||
// This test ensures that the _writeableState.bufferedRequestCount and | ||
// the actual buffered request count are the same | ||
const assert = require('assert'); | ||
|
||
class StreamWritable extends Stream.Writable { | ||
constructor() { | ||
super({ objectMode: true }); | ||
} | ||
|
||
// We need a timeout like on the original issue thread | ||
// otherwise the code will never reach our test case | ||
// this means this should go on the sequential folder. | ||
_write(chunk, encoding, cb) { | ||
setTimeout(cb, common.platformTimeout(10)); | ||
} | ||
} | ||
|
||
const testStream = new StreamWritable(); | ||
testStream.cork(); | ||
|
||
for (let i = 1; i <= 5; i++) { | ||
testStream.write(i, function() { | ||
assert.strictEqual( | ||
testStream._writableState.bufferedRequestCount, | ||
testStream._writableState.getBuffer().length, | ||
'bufferedRequestCount variable is different from the actual length of' + | ||
' the buffer'); | ||
}); | ||
} | ||
|
||
testStream.end(); |