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

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ const assert = require('assert');
88
consthttp2=require('http2');
99
constutil=require('util');
1010

11-
constserver=http2.createServer();
11+
constconnect=util.promisify(http2.connect);
1212

13-
server.listen(0,common.mustCall(()=>{
14-
constport=server.address().port;
15-
server.close(common.mustCall(()=>{
16-
constconnect=util.promisify(http2.connect);
17-
assert.rejects(connect(`http://localhost:${port}`),{
18-
code: 'ECONNREFUSED'
19-
}).then(common.mustCall());
20-
}));
21-
}));
13+
consterror=newError('Unable to resolve hostname');
14+
15+
functionlookup(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)