mirror of
https://github.com/nodejs/node.git
synced 2025-05-07 23:52:40 +00:00

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>
42 lines
948 B
JavaScript
42 lines
948 B
JavaScript
'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);
|
|
}
|