From 3ce7a9a1b5d0f3f3b7f2ad883341fb64f8fbd3cd Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Thu, 23 May 2024 07:51:39 -0400 Subject: [PATCH] test: remove timers from test-tls-socket-close Fixes: https://github.com/nodejs/node/issues/49902 PR-URL: https://github.com/nodejs/node/pull/53019 Reviewed-By: Antoine du Hamel --- test/parallel/test-tls-socket-close.js | 36 +++++++++++++------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/test/parallel/test-tls-socket-close.js b/test/parallel/test-tls-socket-close.js index 0c90593c6af5ca..be941af46eede2 100644 --- a/test/parallel/test-tls-socket-close.js +++ b/test/parallel/test-tls-socket-close.js @@ -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); }); @@ -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); })); @@ -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); }