From 1fbdf47742f915333451224aacc71f9dce2dea35 Mon Sep 17 00:00:00 2001 From: Anatoli Papirovski Date: Sat, 16 Sep 2017 08:56:42 -0400 Subject: [PATCH] test: fix flaky test-http2-session-timeout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Increase server timeout, reduce frequency of calls and unbind timeout after runs are done in order to avoid race conditions. Temporarily moved to sequential. Fixes: https://github.com/nodejs/node/issues/15326 PR-URL: https://github.com/nodejs/node/pull/15338 Reviewed-By: Matteo Collina Reviewed-By: James M Snell Reviewed-By: Yuta Hiroto Reviewed-By: Tobias Nießen --- .../test-http2-session-timeout.js | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) rename test/{parallel => sequential}/test-http2-session-timeout.js (59%) diff --git a/test/parallel/test-http2-session-timeout.js b/test/sequential/test-http2-session-timeout.js similarity index 59% rename from test/parallel/test-http2-session-timeout.js rename to test/sequential/test-http2-session-timeout.js index 27cab3d8bdb22f..a7c6184442aabc 100644 --- a/test/parallel/test-http2-session-timeout.js +++ b/test/sequential/test-http2-session-timeout.js @@ -7,20 +7,22 @@ if (!common.hasCrypto) const h2 = require('http2'); const serverTimeout = common.platformTimeout(200); -const callTimeout = common.platformTimeout(10); +const callTimeout = common.platformTimeout(20); +const minRuns = Math.ceil(serverTimeout / callTimeout) * 2; +const mustNotCall = common.mustNotCall(); const server = h2.createServer(); server.timeout = serverTimeout; server.on('request', (req, res) => res.end()); -server.on('timeout', common.mustNotCall()); +server.on('timeout', mustNotCall); server.listen(0, common.mustCall(() => { const port = server.address().port; const url = `http://localhost:${port}`; const client = h2.connect(url); - makeReq(40); + makeReq(minRuns); function makeReq(attempts) { const request = client.request({ @@ -29,13 +31,17 @@ server.listen(0, common.mustCall(() => { ':scheme': 'http', ':authority': `localhost:${port}`, }); + request.resume(); request.end(); - if (attempts) { - setTimeout(() => makeReq(attempts - 1), callTimeout); - } else { - server.close(); - client.destroy(); - } + request.on('end', () => { + if (attempts) { + setTimeout(() => makeReq(attempts - 1), callTimeout); + } else { + server.removeListener('timeout', mustNotCall); + client.destroy(); + server.close(); + } + }); } }));