From 723159d8d2b5af43f25ddb024a79e052b75ff8b4 Mon Sep 17 00:00:00 2001 From: Nick Sia Date: Mon, 8 Aug 2022 18:09:17 +0800 Subject: [PATCH] test: deflake http-server-request-timeout test parallel/http-server-request-timeouts-mixed test was sometimes failing due to insufficient tolerance between the connection timeout checking interval, and the expected timeout specified in the test. The checking interval was 500ms, and the request was checked for timeout exactly 500ms after the request was expected to timeout. This led to a timing condition where the next check would occur slightly after the request was expected to timeout. This change makes the checking interval more frequent, and decouples the timeout for the check from the checking interval, otherwise the issue would persist. fixes: https://github.com/nodejs/node/issues/43465 --- test/parallel/test-http-server-request-timeouts-mixed.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-http-server-request-timeouts-mixed.js b/test/parallel/test-http-server-request-timeouts-mixed.js index 41b7542c1bdbed0..918aa159b6b3862 100644 --- a/test/parallel/test-http-server-request-timeouts-mixed.js +++ b/test/parallel/test-http-server-request-timeouts-mixed.js @@ -15,7 +15,7 @@ const responseOk = 'HTTP/1.1 200 OK\r\n'; const responseTimeout = 'HTTP/1.1 408 Request Timeout\r\n'; const headersTimeout = common.platformTimeout(2000); -const connectionsCheckingInterval = headersTimeout / 4; +const connectionsCheckingInterval = headersTimeout / 8; const server = createServer({ headersTimeout, @@ -76,7 +76,8 @@ server.listen(0, common.mustCall(() => { // Send the second request, stop in the middle of the headers request2.client.write(requestBodyPart1); - // Send the second request, stop in the middle of the headers + + // Send the third request and stop in the middle of the headers request3.client.write(requestBodyPart1); }, headersTimeout * 0.2); @@ -111,7 +112,7 @@ server.listen(0, common.mustCall(() => { assert(request1.response.startsWith(responseOk)); assert(request2.response.startsWith(responseTimeout)); // It is expired due to headersTimeout - }, headersTimeout * 1.2 + connectionsCheckingInterval); + }, headersTimeout * 1.4); setTimeout(() => { // Complete the body for the fourth request