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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
7edd0a17af
commit
383b1b6d3c
41
test/parallel/test-stream-duplex-end.js
Normal file
41
test/parallel/test-stream-duplex-end.js
Normal file
@ -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);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user