Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6b74064

Browse filesBrowse files
benglMylesBorins
authored andcommitted
test: fix flaky test-http-dns-error
Under some conditions, the error received from getaddrinfo might actually be EAGAIN, meaning the request should be retried. Allowing for 5 retries before erroring out. Also replace one-off function with common.mustNotCall(). PR-URL: #16534 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent eb25252 commit 6b74064
Copy full SHA for 6b74064

File tree

Expand file treeCollapse file tree

1 file changed

+23
-12
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+23
-12
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-http-dns-error.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http-dns-error.js
+23-12Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,41 @@ const http = require('http');
3030
const https = require('https');
3131

3232
const host = '*'.repeat(256);
33+
const MAX_TRIES = 5;
3334

34-
function do_not_call() {
35-
throw new Error('This function should not have been called.');
36-
}
37-
38-
function test(mod) {
39-
35+
function tryGet(mod, tries) {
4036
// Bad host name should not throw an uncatchable exception.
4137
// Ensure that there is time to attach an error listener.
42-
const req1 = mod.get({ host: host, port: 42 }, do_not_call);
43-
req1.on('error', common.mustCall(function(err) {
38+
const req = mod.get({ host: host, port: 42 }, common.mustNotCall());
39+
req.on('error', common.mustCall(function(err) {
40+
if (err.code === 'EAGAIN' && tries < MAX_TRIES) {
41+
tryGet(mod, ++tries);
42+
return;
43+
}
4444
assert.strictEqual(err.code, 'ENOTFOUND');
4545
}));
4646
// http.get() called req1.end() for us
47+
}
4748

48-
const req2 = mod.request({
49+
function tryRequest(mod, tries) {
50+
const req = mod.request({
4951
method: 'GET',
5052
host: host,
5153
port: 42
52-
}, do_not_call);
53-
req2.on('error', common.mustCall(function(err) {
54+
}, common.mustNotCall());
55+
req.on('error', common.mustCall(function(err) {
56+
if (err.code === 'EAGAIN' && tries < MAX_TRIES) {
57+
tryRequest(mod, ++tries);
58+
return;
59+
}
5460
assert.strictEqual(err.code, 'ENOTFOUND');
5561
}));
56-
req2.end();
62+
req.end();
63+
}
64+
65+
function test(mod) {
66+
tryGet(mod, 0);
67+
tryRequest(mod, 0);
5768
}
5869

5970
if (common.hasCrypto) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.