From a77350486de95ec4fd518592fafef03c42afba5c Mon Sep 17 00:00:00 2001 From: Christopher Luke Date: Thu, 16 Mar 2017 14:47:32 -0700 Subject: [PATCH] Made requested changes to test-stream-unpipe-event.js --- test/parallel/test-stream-unpipe-event.js | 108 +++++++++++++--------- 1 file changed, 62 insertions(+), 46 deletions(-) diff --git a/test/parallel/test-stream-unpipe-event.js b/test/parallel/test-stream-unpipe-event.js index 25a8cc147dbc03..befa24253d33f5 100644 --- a/test/parallel/test-stream-unpipe-event.js +++ b/test/parallel/test-stream-unpipe-event.js @@ -16,54 +16,70 @@ class NeverEndReadable extends Readable { _read() {} } -const dest1 = new NullWriteable(); -dest1.on('pipe', common.mustCall(() => {})); -dest1.on('unpipe', common.mustCall(() => {})); -const src1 = new QuickEndReadable(); -src1.pipe(dest1); - - -const dest2 = new NullWriteable(); -dest2.on('pipe', common.mustCall(() => {})); -dest2.on('unpipe', () => { - throw new Error('unpipe should not have been emited'); -}); -const src2 = new NeverEndReadable(); -src2.pipe(dest2); +{ + const dest = new NullWriteable(); + const src = new QuickEndReadable(); + dest.on('pipe', common.mustCall()); + dest.on('unpipe', common.mustCall()); + src.pipe(dest); + setImmediate(() => { + assert.strictEqual(src._readableState.pipesCount, 0); + }); +} -const dest3 = new NullWriteable(); -dest3.on('pipe', common.mustCall(() => {})); -dest3.on('unpipe', common.mustCall(() => {})); -const src3 = new NeverEndReadable(); -src3.pipe(dest3); -src3.unpipe(dest3); +{ + const dest = new NullWriteable(); + const src = new NeverEndReadable(); + dest.on('pipe', common.mustCall()); + dest.on('unpipe', common.mustNotCall('unpipe should not have been emitted')); + src.pipe(dest); + setImmediate(() => { + assert.strictEqual(src._readableState.pipesCount, 1); + }); +} -const dest4 = new NullWriteable(); -dest4.on('pipe', common.mustCall(() => {})); -dest4.on('unpipe', common.mustCall(() => {})); -const src4 = new QuickEndReadable(); -src4.pipe(dest4, {end: false}); +{ + const dest = new NullWriteable(); + const src = new NeverEndReadable(); + dest.on('pipe', common.mustCall()); + dest.on('unpipe', common.mustCall()); + src.pipe(dest); + src.unpipe(dest); + setImmediate(() => { + assert.strictEqual(src._readableState.pipesCount, 0); + }); +} -const dest5 = new NullWriteable(); -dest5.on('pipe', common.mustCall(() => {})); -dest5.on('unpipe', () => { - throw new Error('unpipe should not have been emited'); -}); -const src5 = new NeverEndReadable(); -src5.pipe(dest5, {end: false}); +{ + const dest = new NullWriteable(); + const src = new QuickEndReadable(); + dest.on('pipe', common.mustCall()); + dest.on('unpipe', common.mustCall()); + src.pipe(dest, {end: false}); + setImmediate(() => { + assert.strictEqual(src._readableState.pipesCount, 0); + }); +} -const dest6 = new NullWriteable(); -dest6.on('pipe', common.mustCall(() => {})); -dest6.on('unpipe', common.mustCall(() => {})); -const src6 = new NeverEndReadable(); -src6.pipe(dest6, {end: false}); -src6.unpipe(dest6); +{ + const dest = new NullWriteable(); + const src = new NeverEndReadable(); + dest.on('pipe', common.mustCall()); + dest.on('unpipe', common.mustNotCall('unpipe should not have been emitted')); + src.pipe(dest, {end: false}); + setImmediate(() => { + assert.strictEqual(src._readableState.pipesCount, 1); + }); +} -setImmediate(() => { - assert.strictEqual(src1._readableState.pipesCount, 0); - assert.strictEqual(src2._readableState.pipesCount, 1); - assert.strictEqual(src3._readableState.pipesCount, 0); - assert.strictEqual(src4._readableState.pipesCount, 0); - assert.strictEqual(src5._readableState.pipesCount, 1); - assert.strictEqual(src6._readableState.pipesCount, 0); -}); +{ + const dest = new NullWriteable(); + const src = new NeverEndReadable(); + dest.on('pipe', common.mustCall()); + dest.on('unpipe', common.mustCall()); + src.pipe(dest, {end: false}); + src.unpipe(dest); + setImmediate(() => { + assert.strictEqual(src._readableState.pipesCount, 0); + }); +}