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
  • Loading branch information
lpinca committed May 16, 2024
1 parent 6a2d6df commit c679e6f
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 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 Down Expand Up @@ -45,24 +49,25 @@ function connectClient(server) {
rejectUnauthorized: false
});

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

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

netSocket.destroy();
assert.strictEqual(netSocket.destroyed, 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);
setImmediate(() => {
// Close callbacks are executed after `setImmediate()` callbacks.
assert.strictEqual(netSocketCloseEmitted, false);
assert.strictEqual(serverTlsSocket.destroyed, false);
setImmediate(() => {
assert.strictEqual(netSocketCloseEmitted, true);
});
assert.strictEqual(netSocketCloseEmitted, true);
});
}));
}));
});
});

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

0 comments on commit c679e6f

Please sign in to comment.