mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
985 B
35 lines
985 B
7 years ago
|
'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();
|