Skip to content

Commit 2fa49a3

Browse files
Masashi Hiranotargos
authored andcommitted
test: add tests for end event of stream.Duplex
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>
1 parent 62ca2cf commit 2fa49a3

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const Duplex = require('stream').Duplex;
6+
7+
{
8+
const stream = new Duplex({
9+
read() {}
10+
});
11+
assert.strictEqual(stream.allowHalfOpen, true);
12+
stream.on('finish', common.mustNotCall());
13+
assert.strictEqual(stream.listenerCount('end'), 0);
14+
stream.resume();
15+
stream.push(null);
16+
}
17+
18+
{
19+
const stream = new Duplex({
20+
read() {},
21+
allowHalfOpen: false
22+
});
23+
assert.strictEqual(stream.allowHalfOpen, false);
24+
stream.on('finish', common.mustCall());
25+
assert.strictEqual(stream.listenerCount('end'), 1);
26+
stream.resume();
27+
stream.push(null);
28+
}
29+
30+
{
31+
const stream = new Duplex({
32+
read() {},
33+
allowHalfOpen: false
34+
});
35+
assert.strictEqual(stream.allowHalfOpen, false);
36+
stream._writableState.ended = true;
37+
stream.on('finish', common.mustNotCall());
38+
assert.strictEqual(stream.listenerCount('end'), 1);
39+
stream.resume();
40+
stream.push(null);
41+
}

0 commit comments

Comments
 (0)