Skip to content

Commit

Permalink
fixup! test: fix flaky timeout-delayed-body and headers tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Linkgoron committed Apr 3, 2021
1 parent f4ddbed commit 3b82eee
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
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();
});
}));

0 comments on commit 3b82eee

Please sign in to comment.