Skip to content

Commit d75543d

Browse files
LinkgoronTrott
authored andcommitted
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: #38045 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 4f387c2 commit d75543d

5 files changed

+52
-24
lines changed

test/parallel/test-http-server-request-timeout-delayed-body.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const { connect } = require('net');
99
// after server.requestTimeout if the client
1010
// pauses before start sending the body.
1111

12+
let sendDelayedRequestBody;
1213
const server = createServer(common.mustCall((req, res) => {
1314
let body = '';
1415
req.setEncoding('utf-8');
@@ -22,6 +23,9 @@ const server = createServer(common.mustCall((req, res) => {
2223
res.write(body);
2324
res.end();
2425
});
26+
27+
assert.strictEqual(typeof sendDelayedRequestBody, 'function');
28+
sendDelayedRequestBody();
2529
}));
2630

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

47-
setTimeout(() => {
48-
client.write('12345678901234567890\r\n\r\n');
49-
}, common.platformTimeout(2000)).unref();
51+
sendDelayedRequestBody = common.mustCall(() => {
52+
setTimeout(() => {
53+
client.write('12345678901234567890\r\n\r\n');
54+
}, common.platformTimeout(2000)).unref();
55+
});
5056

5157
const errOrEnd = common.mustCall(function(err) {
5258
console.log(err);

test/parallel/test-http-server-request-timeout-delayed-headers.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ const { connect } = require('net');
88
// This test validates that the server returns 408
99
// after server.requestTimeout if the client
1010
// pauses before start sending the request.
11-
11+
let sendDelayedRequestHeaders;
1212
const server = createServer(common.mustNotCall());
13-
13+
server.on('connection', common.mustCall(() => {
14+
assert.strictEqual(typeof sendDelayedRequestHeaders, 'function');
15+
sendDelayedRequestHeaders();
16+
}));
1417
// 0 seconds is the default
1518
assert.strictEqual(server.requestTimeout, 0);
1619
const requestTimeout = common.platformTimeout(1000);
@@ -39,10 +42,12 @@ server.listen(0, common.mustCall(() => {
3942

4043
client.resume();
4144

42-
setTimeout(() => {
43-
client.write('POST / HTTP/1.1\r\n');
44-
client.write('Content-Length: 20\r\n');
45-
client.write('Connection: close\r\n\r\n');
46-
client.write('12345678901234567890\r\n\r\n');
47-
}, common.platformTimeout(2000)).unref();
45+
sendDelayedRequestHeaders = common.mustCall(() => {
46+
setTimeout(() => {
47+
client.write('POST / HTTP/1.1\r\n');
48+
client.write('Content-Length: 20\r\n');
49+
client.write('Connection: close\r\n\r\n');
50+
client.write('12345678901234567890\r\n\r\n');
51+
}, common.platformTimeout(2000)).unref();
52+
});
4853
}));

test/parallel/test-http-server-request-timeout-interrupted-body.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const { connect } = require('net');
88
// This test validates that the server returns 408
99
// after server.requestTimeout if the client
1010
// pauses sending in the middle of the body.
11-
11+
let sendDelayedRequestBody;
1212
const server = createServer(common.mustCall((req, res) => {
1313
let body = '';
1414
req.setEncoding('utf-8');
@@ -22,6 +22,9 @@ const server = createServer(common.mustCall((req, res) => {
2222
res.write(body);
2323
res.end();
2424
});
25+
26+
assert.strictEqual(typeof sendDelayedRequestBody, 'function');
27+
sendDelayedRequestBody();
2528
}));
2629

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

60-
setTimeout(() => {
61-
client.write('1234567890\r\n\r\n');
62-
}, common.platformTimeout(2000)).unref();
63+
sendDelayedRequestBody = common.mustCall(() => {
64+
setTimeout(() => {
65+
client.write('1234567890\r\n\r\n');
66+
}, common.platformTimeout(2000)).unref();
67+
});
6368
}));

test/parallel/test-http-server-request-timeout-interrupted-headers.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ const { connect } = require('net');
88
// This test validates that the server returns 408
99
// after server.requestTimeout if the client
1010
// pauses sending in the middle of a header.
11-
11+
let sendDelayedRequestHeaders;
1212
const server = createServer(common.mustNotCall());
13+
server.on('connection', common.mustCall(() => {
14+
assert.strictEqual(typeof sendDelayedRequestHeaders, 'function');
15+
sendDelayedRequestHeaders();
16+
}));
1317

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

45-
setTimeout(() => {
46-
client.write('1234567890\r\n\r\n');
47-
}, common.platformTimeout(2000)).unref();
49+
sendDelayedRequestHeaders = common.mustCall(() => {
50+
setTimeout(() => {
51+
client.write('1234567890\r\n\r\n');
52+
}, common.platformTimeout(2000)).unref();
53+
});
4854
}));

test/parallel/test-http-server-request-timeout-upgrade.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ const { connect } = require('net');
77

88
// This test validates that the requestTimeoout
99
// is disabled after the connection is upgraded.
10-
10+
let sendDelayedRequestHeaders;
1111
const server = createServer(common.mustNotCall());
12+
server.on('connection', common.mustCall(() => {
13+
assert.strictEqual(typeof sendDelayedRequestHeaders, 'function');
14+
sendDelayedRequestHeaders();
15+
}));
1216

1317
// 0 seconds is the default
1418
assert.strictEqual(server.requestTimeout, 0);
@@ -48,8 +52,10 @@ server.listen(0, common.mustCall(() => {
4852
client.write('Upgrade: WebSocket\r\n');
4953
client.write('Connection: Upgrade\r\n\r\n');
5054

51-
setTimeout(() => {
52-
client.write('12345678901234567890');
53-
client.end();
54-
}, common.platformTimeout(2000)).unref();
55+
sendDelayedRequestHeaders = common.mustCall(() => {
56+
setTimeout(() => {
57+
client.write('12345678901234567890');
58+
client.end();
59+
}, common.platformTimeout(2000)).unref();
60+
});
5561
}));

0 commit comments

Comments
 (0)