summaryrefslogtreecommitdiff
path: root/test/parallel/test-stream-pipe-await-drain-push-while-write.js
diff options
context:
space:
mode:
authorMark <mail.ormark@gmail.com>2017-01-17 12:58:37 +0200
committerMatteo Collina <hello@matteocollina.com>2017-01-18 08:04:13 -0500
commit21a077ae9ab8b4d70297dcee609d2ca28100c854 (patch)
treee9b44a8354ffde17f176ab7d9c0c2f4f186659f6 /test/parallel/test-stream-pipe-await-drain-push-while-write.js
parent55c42bc6e5602e5a47fb774009cfe9289cb88e71 (diff)
downloadandroid-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-push-while-write.js')
-rw-r--r--test/parallel/test-stream-pipe-await-drain-push-while-write.js22
1 files changed, 20 insertions, 2 deletions
diff --git a/test/parallel/test-stream-pipe-await-drain-push-while-write.js b/test/parallel/test-stream-pipe-await-drain-push-while-write.js
index 1dfdfdb80c..67a8f304c3 100644
--- a/test/parallel/test-stream-pipe-await-drain-push-while-write.js
+++ b/test/parallel/test-stream-pipe-await-drain-push-while-write.js
@@ -1,16 +1,34 @@
'use strict';
const common = require('../common');
const stream = require('stream');
+const assert = require('assert');
+
+const awaitDrainStates = [
+ 1, // after first chunk before callback
+ 1, // after second chunk before callback
+ 0 // resolving chunk pushed after first chunk, awaitDrain is decreased
+];
// A writable stream which pushes data onto the stream which pipes into it,
// but only the first time it's written to. Since it's not paused at this time,
// a second write will occur. If the pipe increases awaitDrain twice, we'll
// never get subsequent chunks because 'drain' is only emitted once.
const writable = new stream.Writable({
- write: common.mustCall((chunk, encoding, cb) => {
+ write: common.mustCall(function(chunk, encoding, cb) {
if (chunk.length === 32 * 1024) { // first chunk
- readable.push(new Buffer(33 * 1024)); // above hwm
+ const beforePush = readable._readableState.awaitDrain;
+ readable.push(new Buffer(34 * 1024)); // above hwm
+ // We should check if awaitDrain counter is increased.
+ const afterPush = readable._readableState.awaitDrain;
+ assert.strictEqual(afterPush - beforePush, 1,
+ 'Counter is not increased for awaitDrain');
}
+
+ assert.strictEqual(
+ awaitDrainStates.shift(),
+ readable._readableState.awaitDrain,
+ 'State variable awaitDrain is not correct.'
+ );
cb();
}, 3)
});