From 9ed7261b57ca05d1a08583bbb0897e35bb78ebdc Mon Sep 17 00:00:00 2001 From: "Italo A. Casas" Date: Mon, 26 Sep 2016 23:25:02 -0400 Subject: [PATCH] test: writable stream needDrain state Add a test for _writableState.needDrain. PR-URL: https://github.com/nodejs/node/pull/8799 Reviewed-By: Colin Ihrig Reviewed-By: Matteo Collina Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Related: https://github.com/nodejs/node/issues/8686 --- .../test-stream-writable-needdrain-state.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 test/parallel/test-stream-writable-needdrain-state.js diff --git a/test/parallel/test-stream-writable-needdrain-state.js b/test/parallel/test-stream-writable-needdrain-state.js new file mode 100644 index 00000000000000..ea5617d997d5ed --- /dev/null +++ b/test/parallel/test-stream-writable-needdrain-state.js @@ -0,0 +1,23 @@ +'use strict'; + +const common = require('../common'); +const stream = require('stream'); +const assert = require('assert'); + +const transform = new stream.Transform({ + transform: _transform, + highWaterMark: 1 +}); + +function _transform(chunk, encoding, cb) { + assert.strictEqual(transform._writableState.needDrain, true); + cb(); +} + +assert.strictEqual(transform._writableState.needDrain, false); + +transform.write('asdasd', common.mustCall(() => { + assert.strictEqual(transform._writableState.needDrain, false); +})); + +assert.strictEqual(transform._writableState.needDrain, true);