Skip to content

Commit

Permalink
test: add tests for end event of stream.Duplex
Browse files Browse the repository at this point in the history
Added tests to check the stream will automatically end the writable side
when readable side ends when allowHalfOpen option is false.

PR-URL: #21325
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com>
  • Loading branch information
Masashi Hirano authored and jasnell committed Jun 22, 2018
1 parent 7edd0a1 commit 383b1b6
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/parallel/test-stream-duplex-end.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const Duplex = require('stream').Duplex;

{
const stream = new Duplex({
read() {}
});
assert.strictEqual(stream.allowHalfOpen, true);
stream.on('finish', common.mustNotCall());
assert.strictEqual(stream.listenerCount('end'), 0);
stream.resume();
stream.push(null);
}

{
const stream = new Duplex({
read() {},
allowHalfOpen: false
});
assert.strictEqual(stream.allowHalfOpen, false);
stream.on('finish', common.mustCall());
assert.strictEqual(stream.listenerCount('end'), 1);
stream.resume();
stream.push(null);
}

{
const stream = new Duplex({
read() {},
allowHalfOpen: false
});
assert.strictEqual(stream.allowHalfOpen, false);
stream._writableState.ended = true;
stream.on('finish', common.mustNotCall());
assert.strictEqual(stream.listenerCount('end'), 1);
stream.resume();
stream.push(null);
}

0 comments on commit 383b1b6

Please sign in to comment.