Skip to content

Commit 2ccf15b

Browse files
committed
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: 3c07b17#commitcomment-38810268 PR-URL: #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>
1 parent 225a03c commit 2ccf15b

File tree

1 file changed

+38
-16
lines changed

1 file changed

+38
-16
lines changed

test/parallel/test-net-allow-half-open.js

+38-16
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,44 @@ const common = require('../common');
44
const assert = require('assert');
55
const net = require('net');
66

7-
const server = net.createServer(common.mustCall((socket) => {
8-
socket.end(Buffer.alloc(1024));
9-
})).listen(0, common.mustCall(() => {
10-
const socket = net.connect(server.address().port);
11-
assert.strictEqual(socket.allowHalfOpen, false);
12-
socket.resume();
13-
socket.on('end', common.mustCall(() => {
14-
process.nextTick(() => {
15-
// Ensure socket is not destroyed straight away
16-
// without proper shutdown.
7+
{
8+
const server = net.createServer(common.mustCall((socket) => {
9+
socket.end(Buffer.alloc(1024));
10+
})).listen(0, common.mustCall(() => {
11+
const socket = net.connect(server.address().port);
12+
assert.strictEqual(socket.allowHalfOpen, false);
13+
socket.resume();
14+
socket.on('end', common.mustCall(() => {
15+
process.nextTick(() => {
16+
// Ensure socket is not destroyed straight away
17+
// without proper shutdown.
18+
assert(!socket.destroyed);
19+
server.close();
20+
});
21+
}));
22+
socket.on('finish', common.mustCall(() => {
1723
assert(!socket.destroyed);
18-
server.close();
19-
});
24+
}));
25+
socket.on('close', common.mustCall());
2026
}));
21-
socket.on('finish', common.mustCall(() => {
22-
assert(!socket.destroyed);
27+
}
28+
29+
{
30+
const server = net.createServer(common.mustCall((socket) => {
31+
socket.end(Buffer.alloc(1024));
32+
})).listen(0, common.mustCall(() => {
33+
const socket = net.connect(server.address().port);
34+
assert.strictEqual(socket.allowHalfOpen, false);
35+
socket.resume();
36+
socket.on('end', common.mustCall(() => {
37+
assert(!socket.destroyed);
38+
}));
39+
socket.end('asd');
40+
socket.on('finish', common.mustCall(() => {
41+
assert(!socket.destroyed);
42+
}));
43+
socket.on('close', common.mustCall(() => {
44+
server.close();
45+
}));
2346
}));
24-
socket.on('close', common.mustCall());
25-
}));
47+
}

0 commit comments

Comments
 (0)