Skip to content

Commit

Permalink
test: remove timers from test-tls-socket-close
Browse files Browse the repository at this point in the history
Fixes: #49902
PR-URL: #53019
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
lpinca authored and targos committed Jun 1, 2024
1 parent 3afeced commit 3ce7a9a
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions test/parallel/test-tls-socket-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const cert = fixtures.readKey('agent2-cert.pem');
let serverTlsSocket;
const tlsServer = tls.createServer({ cert, key }, (socket) => {
serverTlsSocket = socket;
socket.on('data', (chunk) => {
assert.strictEqual(chunk[0], 46);
socket.write('.');
});
socket.on('close', dec);
});

Expand All @@ -25,10 +29,10 @@ let netSocketCloseEmitted = false;
const netServer = net.createServer((socket) => {
netSocket = socket;
tlsServer.emit('connection', socket);
socket.on('close', () => {
socket.on('close', common.mustCall(() => {
netSocketCloseEmitted = true;
assert.strictEqual(serverTlsSocket.destroyed, true);
});
}));
}).listen(0, common.mustCall(() => {
connectClient(netServer);
}));
Expand All @@ -45,24 +49,20 @@ function connectClient(server) {
rejectUnauthorized: false
});

clientTlsSocket.write('foo', 'utf8', common.mustCall(() => {
assert(netSocket);
netSocket.setTimeout(common.platformTimeout(10), common.mustCall(() => {
assert(serverTlsSocket);
clientTlsSocket.write('.');

netSocket.destroy();
assert.strictEqual(netSocket.destroyed, true);
clientTlsSocket.on('data', (chunk) => {
assert.strictEqual(chunk[0], 46);

setImmediate(() => {
// Close callbacks are executed after `setImmediate()` callbacks.
assert.strictEqual(netSocketCloseEmitted, false);
assert.strictEqual(serverTlsSocket.destroyed, false);
setImmediate(() => {
assert.strictEqual(netSocketCloseEmitted, true);
});
});
}));
}));
netSocket.destroy();
assert.strictEqual(netSocket.destroyed, true);

setImmediate(() => {
// Close callbacks are executed after `setImmediate()` callbacks.
assert.strictEqual(netSocketCloseEmitted, false);
assert.strictEqual(serverTlsSocket.destroyed, false);
});
});

clientTlsSocket.on('close', dec);
}
Expand Down

0 comments on commit 3ce7a9a

Please sign in to comment.