| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent eb25252 commit 6b74064
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,30 +30,41 @@ const http = require('http'); | |||
| 30 | 30 | const https = require('https'); | |
| 31 | 31 | ||
| 32 | 32 | const host = '*'.repeat(256); | |
| 33 | + const MAX_TRIES = 5; | ||
| 33 | 34 | ||
| 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) { | ||
| 40 | 36 | // Bad host name should not throw an uncatchable exception. | |
| 41 | 37 | // 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 | + } | ||
| 44 | 44 | assert.strictEqual(err.code, 'ENOTFOUND'); | |
| 45 | 45 | })); | |
| 46 | 46 | // http.get() called req1.end() for us | |
| 47 | + } | ||
| 47 | 48 | ||
| 48 | - const req2 = mod.request({ | ||
| 49 | + function tryRequest(mod, tries) { | ||
| 50 | + const req = mod.request({ | ||
| 49 | 51 | method: 'GET', | |
| 50 | 52 | host: host, | |
| 51 | 53 | 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 | + } | ||
| 54 | 60 | assert.strictEqual(err.code, 'ENOTFOUND'); | |
| 55 | 61 | })); | |
| 56 | - req2.end(); | ||
| 62 | + req.end(); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + function test(mod) { | ||
| 66 | + tryGet(mod, 0); | ||
| 67 | + tryRequest(mod, 0); | ||
| 57 | 68 | } | |
| 58 | 69 | ||
| 59 | 70 | if (common.hasCrypto) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments