summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBryan English <bryan@bryanenglish.com>2017-10-26 16:20:45 -0700
committerRuben Bridgewater <ruben@bridgewater.de>2018-02-01 09:52:58 +0100
commit7d4b7724ec53cbec08b51033b2406f927d5548eb (patch)
treee8238fe279d0e8608a96fd002a6a3c1ba0d9c7f3 /test
parentac7f1e339c8043870d6af29191f1bcd3515fc091 (diff)
downloadandroid-node-v8-7d4b7724ec53cbec08b51033b2406f927d5548eb.tar.gz
android-node-v8-7d4b7724ec53cbec08b51033b2406f927d5548eb.tar.bz2
android-node-v8-7d4b7724ec53cbec08b51033b2406f927d5548eb.zip
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: https://github.com/nodejs/node/pull/16534 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-http-dns-error.js35
1 files changed, 23 insertions, 12 deletions
diff --git a/test/parallel/test-http-dns-error.js b/test/parallel/test-http-dns-error.js
index 723b710647..900cf40e6b 100644
--- a/test/parallel/test-http-dns-error.js
+++ b/test/parallel/test-http-dns-error.js
@@ -30,30 +30,41 @@ const http = require('http');
const https = require('https');
const host = '*'.repeat(256);
+const MAX_TRIES = 5;
-function do_not_call() {
- throw new Error('This function should not have been called.');
-}
-
-function test(mod) {
-
+function tryGet(mod, tries) {
// Bad host name should not throw an uncatchable exception.
// Ensure that there is time to attach an error listener.
- const req1 = mod.get({ host: host, port: 42 }, do_not_call);
- req1.on('error', common.mustCall(function(err) {
+ const req = mod.get({ host: host, port: 42 }, common.mustNotCall());
+ req.on('error', common.mustCall(function(err) {
+ if (err.code === 'EAGAIN' && tries < MAX_TRIES) {
+ tryGet(mod, ++tries);
+ return;
+ }
assert.strictEqual(err.code, 'ENOTFOUND');
}));
// http.get() called req1.end() for us
+}
- const req2 = mod.request({
+function tryRequest(mod, tries) {
+ const req = mod.request({
method: 'GET',
host: host,
port: 42
- }, do_not_call);
- req2.on('error', common.mustCall(function(err) {
+ }, common.mustNotCall());
+ req.on('error', common.mustCall(function(err) {
+ if (err.code === 'EAGAIN' && tries < MAX_TRIES) {
+ tryRequest(mod, ++tries);
+ return;
+ }
assert.strictEqual(err.code, 'ENOTFOUND');
}));
- req2.end();
+ req.end();
+}
+
+function test(mod) {
+ tryGet(mod, 0);
+ tryRequest(mod, 0);
}
if (common.hasCrypto) {