diff --git a/test/parallel/test-tls-friendly-error-message.js b/test/parallel/test-tls-friendly-error-message.js index b52918be27ac9b..4ae9d3f3f956d4 100644 --- a/test/parallel/test-tls-friendly-error-message.js +++ b/test/parallel/test-tls-friendly-error-message.js @@ -31,14 +31,15 @@ const tls = require('tls'); const key = fixtures.readKey('agent1-key.pem'); const cert = fixtures.readKey('agent1-cert.pem'); -tls.createServer({ key, cert }, common.mustCall(function(conn) { - conn.end(); +tls.createServer({ key, cert }).on('connection', common.mustCall(function() { + // Server only receives one TCP connection, stop listening when that + // connection is destroyed by the client, which it should do after the cert is + // rejected as unauthorized. this.close(); })).listen(0, common.mustCall(function() { const options = { port: this.address().port, rejectUnauthorized: true }; tls.connect(options).on('error', common.mustCall(function(err) { assert.strictEqual(err.code, 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'); assert.strictEqual(err.message, 'unable to verify the first certificate'); - this.destroy(); })); }));