From 90f3e2ff86198d78551ac94bd3966cb1c69bdfac Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 19 Aug 2018 09:15:04 -0700 Subject: [PATCH 1/3] test: fix flaky http timeout test There is no guarantee that a timeout won't be delayed considerably due to unrelated activity on the host. Instead of checking that the timeout happens within a certain tolerance, simply check that it did not happen too soon. Fixes: https://github.com/nodejs/node/issues/22041 --- .../sequential/test-http-client-timeout-option-with-agent.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/sequential/test-http-client-timeout-option-with-agent.js b/test/sequential/test-http-client-timeout-option-with-agent.js index a7f750a42e557b..63f683975dc9d0 100644 --- a/test/sequential/test-http-client-timeout-option-with-agent.js +++ b/test/sequential/test-http-client-timeout-option-with-agent.js @@ -42,8 +42,9 @@ function doRequest() { timeout_events += 1; const duration = Date.now() - start; // The timeout event cannot be precisely timed. It will delay - // some number of milliseconds, so test it in second units. - assert.strictEqual(duration / 1000 | 0, HTTP_CLIENT_TIMEOUT / 1000); + // some number of milliseconds. + assert.ok(duration >= HTTP_CLIENT_TIMEOUT, + `${duration} < ${HTTP_CLIENT_TIMEOUT}`); })); req.end(); From 0cd6873cb3b19a30d822c34b539f509f5bc9ae8d Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 19 Aug 2018 16:53:45 -0700 Subject: [PATCH 2/3] test: move http timeout test to parallel test-http-client-timeout-option-with-agent no longer checks that the timeout happens within a certain tolerance so it can be moved to the parallel test suite. --- .../test-http-client-timeout-option-with-agent.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/{sequential => parallel}/test-http-client-timeout-option-with-agent.js (100%) diff --git a/test/sequential/test-http-client-timeout-option-with-agent.js b/test/parallel/test-http-client-timeout-option-with-agent.js similarity index 100% rename from test/sequential/test-http-client-timeout-option-with-agent.js rename to test/parallel/test-http-client-timeout-option-with-agent.js From d194aaea6d1b1e1f3ff4b1fda5fe20a81aed5637 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 19 Aug 2018 16:56:11 -0700 Subject: [PATCH 3/3] test: improve assert message in http timeout test --- test/parallel/test-http-client-timeout-option-with-agent.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-http-client-timeout-option-with-agent.js b/test/parallel/test-http-client-timeout-option-with-agent.js index 63f683975dc9d0..26c93ec55bc903 100644 --- a/test/parallel/test-http-client-timeout-option-with-agent.js +++ b/test/parallel/test-http-client-timeout-option-with-agent.js @@ -43,8 +43,10 @@ function doRequest() { const duration = Date.now() - start; // The timeout event cannot be precisely timed. It will delay // some number of milliseconds. - assert.ok(duration >= HTTP_CLIENT_TIMEOUT, - `${duration} < ${HTTP_CLIENT_TIMEOUT}`); + assert.ok( + duration >= HTTP_CLIENT_TIMEOUT, + `duration ${duration}ms less than timeout ${HTTP_CLIENT_TIMEOUT}ms` + ); })); req.end();