mirror of https://github.com/nodejs/node.git
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: https://github.com/nodejs/node/pull/57144 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
parent
c6d6be2c3b
commit
315244e59e
|
@ -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());
|
||||
|
|
Loading…
Reference in New Issue