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); }