diff options
author | Mark <mail.ormark@gmail.com> | 2017-01-17 12:58:37 +0200 |
---|---|---|
committer | Matteo Collina <hello@matteocollina.com> | 2017-01-18 08:04:13 -0500 |
commit | 21a077ae9ab8b4d70297dcee609d2ca28100c854 (patch) | |
tree | e9b44a8354ffde17f176ab7d9c0c2f4f186659f6 /test/parallel/test-stream-pipe-await-drain.js | |
parent | 55c42bc6e5602e5a47fb774009cfe9289cb88e71 (diff) | |
download | android-node-v8-21a077ae9ab8b4d70297dcee609d2ca28100c854.tar.gz android-node-v8-21a077ae9ab8b4d70297dcee609d2ca28100c854.tar.bz2 android-node-v8-21a077ae9ab8b4d70297dcee609d2ca28100c854.zip |
test: tests for _readableStream.awaitDrain
Fixes: https://github.com/nodejs/node/issues/8684
PR-URL: https://github.com/nodejs/node/pull/8914
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'test/parallel/test-stream-pipe-await-drain.js')
-rw-r--r-- | test/parallel/test-stream-pipe-await-drain.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/test/parallel/test-stream-pipe-await-drain.js b/test/parallel/test-stream-pipe-await-drain.js index fba99ed456..fc822bb60b 100644 --- a/test/parallel/test-stream-pipe-await-drain.js +++ b/test/parallel/test-stream-pipe-await-drain.js @@ -1,12 +1,14 @@ 'use strict'; const common = require('../common'); const stream = require('stream'); +const assert = require('assert'); // This is very similar to test-stream-pipe-cleanup-pause.js. const reader = new stream.Readable(); const writer1 = new stream.Writable(); const writer2 = new stream.Writable(); +const writer3 = new stream.Writable(); // 560000 is chosen here because it is larger than the (default) highWaterMark // and will cause `.write()` to return false @@ -19,7 +21,10 @@ writer1._write = common.mustCall(function(chunk, encoding, cb) { this.emit('chunk-received'); cb(); }, 1); + writer1.once('chunk-received', function() { + assert.strictEqual(reader._readableState.awaitDrain, 0, + 'initial value is not 0'); setImmediate(function() { // This one should *not* get through to writer1 because writer2 is not // "done" processing. @@ -29,12 +34,26 @@ writer1.once('chunk-received', function() { // A "slow" consumer: writer2._write = common.mustCall(function(chunk, encoding, cb) { + assert.strictEqual( + reader._readableState.awaitDrain, 1, + 'awaitDrain isn\'t 1 after first push' + ); // Not calling cb here to "simulate" slow stream. + // This should be called exactly once, since the first .write() call + // will return false. +}, 1); +writer3._write = common.mustCall(function(chunk, encoding, cb) { + assert.strictEqual( + reader._readableState.awaitDrain, 2, + 'awaitDrain isn\'t 2 after second push' + ); + // Not calling cb here to "simulate" slow stream. // This should be called exactly once, since the first .write() call // will return false. }, 1); reader.pipe(writer1); reader.pipe(writer2); +reader.pipe(writer3); reader.push(buffer); |