From f302bc13db25b0067b226e9fc68796e54815ff6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sun, 24 Apr 2022 17:59:37 +0200 Subject: [PATCH] test: fix flaky HTTP server tests Refs: https://github.com/nodejs/node/pull/41263 PR-URL: https://github.com/nodejs/node/pull/42846 Fixes: https://github.com/nodejs/node/issues/42741 Reviewed-By: Rich Trott Reviewed-By: Luigi Pinca Reviewed-By: Mohammed Keyvanzadeh Reviewed-By: Darshan Sen Reviewed-By: Paolo Insogna --- ...st-http-server-request-timeout-keepalive.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/test/parallel/test-http-server-request-timeout-keepalive.js b/test/parallel/test-http-server-request-timeout-keepalive.js index 77fde867e9b540..444e15f57afb89 100644 --- a/test/parallel/test-http-server-request-timeout-keepalive.js +++ b/test/parallel/test-http-server-request-timeout-keepalive.js @@ -14,11 +14,6 @@ function performRequestWithDelay(client, firstDelay, secondDelay) { client.resume(); client.write('GET / HTTP/1.1\r\n'); - firstDelay = common.platformTimeout(firstDelay); - secondDelay = common.platformTimeout(secondDelay); - - console.log('performRequestWithDelay', firstDelay, secondDelay); - setTimeout(() => { client.write('Connection: '); }, firstDelay).unref(); @@ -29,14 +24,19 @@ function performRequestWithDelay(client, firstDelay, secondDelay) { }, firstDelay + secondDelay).unref(); } -const server = createServer(common.mustCallAtLeast((req, res) => { +const requestTimeout = common.platformTimeout(2000); +const server = createServer({ + headersTimeout: 0, + requestTimeout, + keepAliveTimeout: 0, + connectionsCheckingInterval: requestTimeout / 4 +}, common.mustCallAtLeast((req, res) => { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end(); })); // 0 seconds is the default assert.strictEqual(server.requestTimeout, 0); -const requestTimeout = common.platformTimeout(1000); server.requestTimeout = requestTimeout; assert.strictEqual(server.requestTimeout, requestTimeout); @@ -58,9 +58,7 @@ server.listen(0, common.mustCall(() => { 'HTTP/1.1 200 OK' ); - const defer = common.platformTimeout(server.requestTimeout * 1.5); - - console.log('defer by', defer); + const defer = requestTimeout * 1.5; // Wait some time to make sure requestTimeout // does not interfere with keep alive