Skip to content

Commit 315244e

Browse files
lpincatargos
authored andcommitted
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. PR-URL: #57144 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent c6d6be2 commit 315244e

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

test/parallel/test-http2-client-promisify-connect-error.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ const assert = require('assert');
88
const http2 = require('http2');
99
const util = require('util');
1010

11-
const server = http2.createServer();
11+
const connect = util.promisify(http2.connect);
1212

13-
server.listen(0, common.mustCall(() => {
14-
const port = server.address().port;
15-
server.close(common.mustCall(() => {
16-
const connect = util.promisify(http2.connect);
17-
assert.rejects(connect(`http://localhost:${port}`), {
18-
code: 'ECONNREFUSED'
19-
}).then(common.mustCall());
20-
}));
21-
}));
13+
const error = new Error('Unable to resolve hostname');
14+
15+
function lookup(hostname, options, callback) {
16+
callback(error);
17+
}
18+
19+
assert.rejects(
20+
connect('http://hostname', { lookup }),
21+
error,
22+
).then(common.mustCall());

0 commit comments

Comments
 (0)