From f001398b3d2aa5152fdef0a97322e296e5c7428d Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 29 Sep 2017 11:09:19 -0700 Subject: [PATCH 1/3] test: skip test if host is too slow test-http-server-consumed-timeout will fail if the host is sufficiently loaded that a 25ms interval takes more than 200ms to be invoked. Skip the test in that situation. Fixes: https://github.com/nodejs/node/issues/14312 --- .../test-http-server-consumed-timeout.js | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/test/sequential/test-http-server-consumed-timeout.js b/test/sequential/test-http-server-consumed-timeout.js index e6157a0a1d9200..a4b2772ee59183 100644 --- a/test/sequential/test-http-server-consumed-timeout.js +++ b/test/sequential/test-http-server-consumed-timeout.js @@ -3,18 +3,26 @@ const common = require('../common'); const http = require('http'); +let time = Date.now(); +let intervalWasInvoked = false; +const TIMEOUT = common.platformTimeout(200); + const server = http.createServer((req, res) => { server.close(); res.writeHead(200); res.flushHeaders(); - req.setTimeout(common.platformTimeout(200), - common.mustNotCall('Request timeout should not fire')); + req.setTimeout(TIMEOUT, () => { + if (!intervalWasInvoked) + common.skip('interval was not invoked quickly enough for test'); + common.fail('Request timeout should not fire'); + }); + req.resume(); - req.once('end', common.mustCall(() => { + req.once('end', () => { res.end(); - })); + }); }); server.listen(0, common.mustCall(() => { @@ -23,12 +31,20 @@ server.listen(0, common.mustCall(() => { method: 'POST' }, (res) => { const interval = setInterval(() => { + intervalWasInvoked = true; + // If machine is busy enough that the interval takes more than TIMEOUT ms + // to be invoked, skip the test. + const now = Date.now(); + console.log('diff is ' + (now - time)); + if (time < now - TIMEOUT) + common.skip('interval is not invoked quickly enough for test'); + time = now; req.write('a'); }, common.platformTimeout(25)); setTimeout(() => { clearInterval(interval); req.end(); - }, common.platformTimeout(200)); + }, TIMEOUT); }); req.write('.'); })); From 28ad47b0e2f62ad4d30610563e152ef4f94eadf7 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 29 Sep 2017 13:12:29 -0700 Subject: [PATCH 2/3] squash: remove console.log() --- test/sequential/test-http-server-consumed-timeout.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/sequential/test-http-server-consumed-timeout.js b/test/sequential/test-http-server-consumed-timeout.js index a4b2772ee59183..205880b58169a8 100644 --- a/test/sequential/test-http-server-consumed-timeout.js +++ b/test/sequential/test-http-server-consumed-timeout.js @@ -35,7 +35,6 @@ server.listen(0, common.mustCall(() => { // If machine is busy enough that the interval takes more than TIMEOUT ms // to be invoked, skip the test. const now = Date.now(); - console.log('diff is ' + (now - time)); if (time < now - TIMEOUT) common.skip('interval is not invoked quickly enough for test'); time = now; From 77ea4bf58fd203b953884f3c35d158b47b93e629 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 29 Sep 2017 15:39:40 -0700 Subject: [PATCH 3/3] squash: refack nits --- test/sequential/test-http-server-consumed-timeout.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/sequential/test-http-server-consumed-timeout.js b/test/sequential/test-http-server-consumed-timeout.js index 205880b58169a8..abe100c1907e0f 100644 --- a/test/sequential/test-http-server-consumed-timeout.js +++ b/test/sequential/test-http-server-consumed-timeout.js @@ -15,7 +15,7 @@ const server = http.createServer((req, res) => { req.setTimeout(TIMEOUT, () => { if (!intervalWasInvoked) - common.skip('interval was not invoked quickly enough for test'); + return common.skip('interval was not invoked quickly enough for test'); common.fail('Request timeout should not fire'); }); @@ -35,8 +35,8 @@ server.listen(0, common.mustCall(() => { // If machine is busy enough that the interval takes more than TIMEOUT ms // to be invoked, skip the test. const now = Date.now(); - if (time < now - TIMEOUT) - common.skip('interval is not invoked quickly enough for test'); + if (now - time > TIMEOUT) + return common.skip('interval is not invoked quickly enough for test'); time = now; req.write('a'); }, common.platformTimeout(25));