Skip to content

Commit

Permalink
Made requested changes to test-stream-unpipe-event.js
Browse files Browse the repository at this point in the history
  • Loading branch information
zaide-chris committed Apr 7, 2017
1 parent 850cd09 commit a773504
Showing 1 changed file with 62 additions and 46 deletions.
108 changes: 62 additions & 46 deletions test/parallel/test-stream-unpipe-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

0 comments on commit a773504

Please sign in to comment.