test: fix flaky timeout-delayed-body and headers tests

fix the flaky test-http-server-request-timeout-delayed-body
and test-http-server-request-timeout-delayed-headers which
sometimes fail on slow systems.

PR-URL: https://github.com/nodejs/node/pull/38045
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Nitzan Uziely 2021-04-02 18:55:57 +03:00 committed by Rich Trott
parent 4f387c25cb
commit d75543d8b5
5 changed files with 52 additions and 24 deletions

View file

@ -8,9 +8,12 @@ const { connect } = require('net');
// This test validates that the server returns 408
// after server.requestTimeout if the client
// pauses before start sending the request.
let sendDelayedRequestHeaders;
const server = createServer(common.mustNotCall());
server.on('connection', common.mustCall(() => {
assert.strictEqual(typeof sendDelayedRequestHeaders, 'function');
sendDelayedRequestHeaders();
}));
// 0 seconds is the default
assert.strictEqual(server.requestTimeout, 0);
const requestTimeout = common.platformTimeout(1000);
@ -39,10 +42,12 @@ server.listen(0, common.mustCall(() => {
client.resume();
setTimeout(() => {
client.write('POST / HTTP/1.1\r\n');
client.write('Content-Length: 20\r\n');
client.write('Connection: close\r\n\r\n');
client.write('12345678901234567890\r\n\r\n');
}, common.platformTimeout(2000)).unref();
sendDelayedRequestHeaders = common.mustCall(() => {
setTimeout(() => {
client.write('POST / HTTP/1.1\r\n');
client.write('Content-Length: 20\r\n');
client.write('Connection: close\r\n\r\n');
client.write('12345678901234567890\r\n\r\n');
}, common.platformTimeout(2000)).unref();
});
}));