mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
test: ensure finish is emitted before destroy
Adds a test to ensure that 'finish' is emitted
before the socket is destroyed by allow half-open
enforcer.
Refs: 3c07b1793c (commitcomment-38810268)
PR-URL: https://github.com/nodejs/node/pull/33137
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
@@ -4,22 +4,44 @@ const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const net = require('net');
|
||||
|
||||
const server = net.createServer(common.mustCall((socket) => {
|
||||
socket.end(Buffer.alloc(1024));
|
||||
})).listen(0, common.mustCall(() => {
|
||||
const socket = net.connect(server.address().port);
|
||||
assert.strictEqual(socket.allowHalfOpen, false);
|
||||
socket.resume();
|
||||
socket.on('end', common.mustCall(() => {
|
||||
process.nextTick(() => {
|
||||
// Ensure socket is not destroyed straight away
|
||||
// without proper shutdown.
|
||||
{
|
||||
const server = net.createServer(common.mustCall((socket) => {
|
||||
socket.end(Buffer.alloc(1024));
|
||||
})).listen(0, common.mustCall(() => {
|
||||
const socket = net.connect(server.address().port);
|
||||
assert.strictEqual(socket.allowHalfOpen, false);
|
||||
socket.resume();
|
||||
socket.on('end', common.mustCall(() => {
|
||||
process.nextTick(() => {
|
||||
// Ensure socket is not destroyed straight away
|
||||
// without proper shutdown.
|
||||
assert(!socket.destroyed);
|
||||
server.close();
|
||||
});
|
||||
}));
|
||||
socket.on('finish', common.mustCall(() => {
|
||||
assert(!socket.destroyed);
|
||||
}));
|
||||
socket.on('close', common.mustCall());
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
const server = net.createServer(common.mustCall((socket) => {
|
||||
socket.end(Buffer.alloc(1024));
|
||||
})).listen(0, common.mustCall(() => {
|
||||
const socket = net.connect(server.address().port);
|
||||
assert.strictEqual(socket.allowHalfOpen, false);
|
||||
socket.resume();
|
||||
socket.on('end', common.mustCall(() => {
|
||||
assert(!socket.destroyed);
|
||||
}));
|
||||
socket.end('asd');
|
||||
socket.on('finish', common.mustCall(() => {
|
||||
assert(!socket.destroyed);
|
||||
}));
|
||||
socket.on('close', common.mustCall(() => {
|
||||
server.close();
|
||||
});
|
||||
}));
|
||||
}));
|
||||
socket.on('finish', common.mustCall(() => {
|
||||
assert(!socket.destroyed);
|
||||
}));
|
||||
socket.on('close', common.mustCall());
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user