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 <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ujjwal Sharma <[email protected]>
  • Loading branch information
Masashi Hirano authored and targos committed Jun 24, 2018
1 parent 62ca2cf commit 2fa49a3
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 2fa49a3

Please sign in to comment.