From 42a53b87c600bd2f8e45e548de8fb1e0ded64126 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Thu, 20 Feb 2025 09:26:07 +0100 Subject: [PATCH] test: simplify test-http2-client-promisify-connect-error There is no need to try to create a TCP connection that fails due to a missing listening server. Also, the port used for the connection might be used by another process when the connection is made. --- ...st-http2-client-promisify-connect-error.js | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/test/parallel/test-http2-client-promisify-connect-error.js b/test/parallel/test-http2-client-promisify-connect-error.js index b3c8bc980aac67..4cd4f48e4c8bbf 100644 --- a/test/parallel/test-http2-client-promisify-connect-error.js +++ b/test/parallel/test-http2-client-promisify-connect-error.js @@ -8,14 +8,15 @@ const assert = require('assert'); const http2 = require('http2'); const util = require('util'); -const server = http2.createServer(); +const connect = util.promisify(http2.connect); -server.listen(0, common.mustCall(() => { - const port = server.address().port; - server.close(common.mustCall(() => { - const connect = util.promisify(http2.connect); - assert.rejects(connect(`http://localhost:${port}`), { - code: 'ECONNREFUSED' - }).then(common.mustCall()); - })); -})); +const error = new Error('Unable to resolve hostname'); + +function lookup(hostname, options, callback) { + callback(error); +} + +assert.rejects( + connect('http://hostname', { lookup }), + error, +).then(common.mustCall());