GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: fix flaky test-http-dns-error · nodejs/node@a1fb263

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/parallel
    • test-http-dns-error.js
Expand file treeCollapse file tree
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)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.