Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix flaky timeout-request body and headers tests #38045

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions test/parallel/test-http-server-request-timeout-delayed-body.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const { connect } = require('net');
// after server.requestTimeout if the client
// pauses before start sending the body.

let sendDelayedRequestBody;
const server = createServer(common.mustCall((req, res) => {
let body = '';
req.setEncoding('utf-8');
Expand All @@ -22,6 +23,9 @@ const server = createServer(common.mustCall((req, res) => {
res.write(body);
res.end();
});

assert.strictEqual(typeof sendDelayedRequestBody, 'function');
sendDelayedRequestBody();
}));

// 0 seconds is the default
Expand All @@ -44,9 +48,11 @@ server.listen(0, common.mustCall(() => {
client.write('Connection: close\r\n');
client.write('\r\n');

setTimeout(() => {
client.write('12345678901234567890\r\n\r\n');
}, common.platformTimeout(2000)).unref();
sendDelayedRequestBody = common.mustCall(() => {
setTimeout(() => {
client.write('12345678901234567890\r\n\r\n');
}, common.platformTimeout(2000)).unref();
});

const errOrEnd = common.mustCall(function(err) {
console.log(err);
Expand Down
21 changes: 13 additions & 8 deletions test/parallel/test-http-server-request-timeout-delayed-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
});
}));
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { connect } = require('net');
// This test validates that the server returns 408
// after server.requestTimeout if the client
// pauses sending in the middle of the body.

let sendDelayedRequestBody;
const server = createServer(common.mustCall((req, res) => {
let body = '';
req.setEncoding('utf-8');
Expand All @@ -22,6 +22,9 @@ const server = createServer(common.mustCall((req, res) => {
res.write(body);
res.end();
});

assert.strictEqual(typeof sendDelayedRequestBody, 'function');
sendDelayedRequestBody();
}));

// 0 seconds is the default
Expand Down Expand Up @@ -57,7 +60,9 @@ server.listen(0, common.mustCall(() => {
client.write('\r\n');
client.write('1234567890');

setTimeout(() => {
client.write('1234567890\r\n\r\n');
}, common.platformTimeout(2000)).unref();
sendDelayedRequestBody = common.mustCall(() => {
setTimeout(() => {
client.write('1234567890\r\n\r\n');
}, common.platformTimeout(2000)).unref();
});
}));
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ const { connect } = require('net');
// This test validates that the server returns 408
// after server.requestTimeout if the client
// pauses sending in the middle of a header.

let sendDelayedRequestHeaders;
const server = createServer(common.mustNotCall());
server.on('connection', common.mustCall(() => {
assert.strictEqual(typeof sendDelayedRequestHeaders, 'function');
sendDelayedRequestHeaders();
}));

// 120 seconds is the default
assert.strictEqual(server.requestTimeout, 0);
Expand Down Expand Up @@ -42,7 +46,9 @@ server.listen(0, common.mustCall(() => {
client.write('Connection: close\r\n');
client.write('X-CRASH: ');

setTimeout(() => {
client.write('1234567890\r\n\r\n');
}, common.platformTimeout(2000)).unref();
sendDelayedRequestHeaders = common.mustCall(() => {
setTimeout(() => {
client.write('1234567890\r\n\r\n');
}, common.platformTimeout(2000)).unref();
});
}));
16 changes: 11 additions & 5 deletions test/parallel/test-http-server-request-timeout-upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ const { connect } = require('net');

// This test validates that the requestTimeoout
// is disabled after the connection is upgraded.

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);
Expand Down Expand Up @@ -48,8 +52,10 @@ server.listen(0, common.mustCall(() => {
client.write('Upgrade: WebSocket\r\n');
client.write('Connection: Upgrade\r\n\r\n');

setTimeout(() => {
client.write('12345678901234567890');
client.end();
}, common.platformTimeout(2000)).unref();
sendDelayedRequestHeaders = common.mustCall(() => {
setTimeout(() => {
client.write('12345678901234567890');
client.end();
}, common.platformTimeout(2000)).unref();
});
}));