Skip to content

Commit

Permalink
test: fix flaky HTTP server tests
Browse files Browse the repository at this point in the history
Refs: #41263

PR-URL: #42846
Fixes: #42741
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
Reviewed-By: Paolo Insogna <[email protected]>
  • Loading branch information
tniessen authored and juanarbol committed May 31, 2022
1 parent 9e815c5 commit f302bc1
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions test/parallel/test-http-server-request-timeout-keepalive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);

Expand All @@ -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
Expand Down

0 comments on commit f302bc1

Please sign in to comment.