Skip to content

Commit e20f357

Browse files
Trottjasnell
authored andcommitted
test: improve test-https-server-keep-alive-timeout
The test is flaky under load. These changes greatly improve reliability. * Use a recurring interval to determine when the test should end rather than a timer. * Increase server timeout to 500ms to allow for events being delayed by system load Changing to an interval has the added benefit of reducing the test run time from over 2 seconds to under 1 second. Fixes: #13307 PR-URL: #13312 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Alexey Orlenko <[email protected]>
1 parent 1729574 commit e20f357

File tree

1 file changed

+10
-28
lines changed

1 file changed

+10
-28
lines changed

test/parallel/test-https-server-keep-alive-timeout.js

+10-28
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,20 @@ function run() {
3030
}
3131

3232
test(function serverKeepAliveTimeoutWithPipeline(cb) {
33-
let socket;
34-
let destroyedSockets = 0;
35-
let timeoutCount = 0;
3633
let requestCount = 0;
3734
process.on('exit', function() {
38-
assert.strictEqual(timeoutCount, 1);
3935
assert.strictEqual(requestCount, 3);
40-
assert.strictEqual(destroyedSockets, 1);
4136
});
4237
const server = https.createServer(serverOptions, (req, res) => {
43-
socket = req.socket;
4438
requestCount++;
4539
res.end();
4640
});
47-
server.setTimeout(200, (socket) => {
48-
timeoutCount++;
41+
server.setTimeout(500, common.mustCall((socket) => {
42+
// End this test and call `run()` for the next test (if any).
4943
socket.destroy();
50-
});
44+
server.close();
45+
cb();
46+
}));
5147
server.keepAliveTimeout = 50;
5248
server.listen(0, common.mustCall(() => {
5349
const options = {
@@ -60,32 +56,23 @@ test(function serverKeepAliveTimeoutWithPipeline(cb) {
6056
c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n');
6157
c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n');
6258
});
63-
setTimeout(() => {
64-
server.close();
65-
if (socket.destroyed) destroyedSockets++;
66-
cb();
67-
}, 1000);
6859
}));
6960
});
7061

7162
test(function serverNoEndKeepAliveTimeoutWithPipeline(cb) {
72-
let socket;
73-
let destroyedSockets = 0;
74-
let timeoutCount = 0;
7563
let requestCount = 0;
7664
process.on('exit', () => {
77-
assert.strictEqual(timeoutCount, 1);
7865
assert.strictEqual(requestCount, 3);
79-
assert.strictEqual(destroyedSockets, 1);
8066
});
8167
const server = https.createServer(serverOptions, (req, res) => {
82-
socket = req.socket;
8368
requestCount++;
8469
});
85-
server.setTimeout(200, (socket) => {
86-
timeoutCount++;
70+
server.setTimeout(500, common.mustCall((socket) => {
71+
// End this test and call `run()` for the next test (if any).
8772
socket.destroy();
88-
});
73+
server.close();
74+
cb();
75+
}));
8976
server.keepAliveTimeout = 50;
9077
server.listen(0, common.mustCall(() => {
9178
const options = {
@@ -98,10 +85,5 @@ test(function serverNoEndKeepAliveTimeoutWithPipeline(cb) {
9885
c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n');
9986
c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n');
10087
});
101-
setTimeout(() => {
102-
server.close();
103-
if (socket && socket.destroyed) destroyedSockets++;
104-
cb();
105-
}, 1000);
10688
}));
10789
});

0 commit comments

Comments
 (0)