Skip to content

Commit 1c7fbdc

Browse files
Trottrvagg
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 <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
1 parent e9ae4aa commit 1c7fbdc

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

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,20 @@ function run() {
2626
}
2727

2828
test(function serverKeepAliveTimeoutWithPipeline(cb) {
29-
let socket;
30-
let destroyedSockets = 0;
31-
let timeoutCount = 0;
3229
let requestCount = 0;
3330
process.on('exit', function() {
34-
assert.strictEqual(timeoutCount, 1);
3531
assert.strictEqual(requestCount, 3);
36-
assert.strictEqual(destroyedSockets, 1);
3732
});
3833
const server = https.createServer(serverOptions, (req, res) => {
39-
socket = req.socket;
4034
requestCount++;
4135
res.end();
4236
});
43-
server.setTimeout(200, (socket) => {
44-
timeoutCount++;
37+
server.setTimeout(500, common.mustCall((socket) => {
38+
// End this test and call `run()` for the next test (if any).
4539
socket.destroy();
46-
});
40+
server.close();
41+
cb();
42+
}));
4743
server.keepAliveTimeout = 50;
4844
server.listen(0, common.mustCall(() => {
4945
const options = {
@@ -56,32 +52,23 @@ test(function serverKeepAliveTimeoutWithPipeline(cb) {
5652
c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n');
5753
c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n');
5854
});
59-
setTimeout(() => {
60-
server.close();
61-
if (socket.destroyed) destroyedSockets++;
62-
cb();
63-
}, 1000);
6455
}));
6556
});
6657

6758
test(function serverNoEndKeepAliveTimeoutWithPipeline(cb) {
68-
let socket;
69-
let destroyedSockets = 0;
70-
let timeoutCount = 0;
7159
let requestCount = 0;
7260
process.on('exit', () => {
73-
assert.strictEqual(timeoutCount, 1);
7461
assert.strictEqual(requestCount, 3);
75-
assert.strictEqual(destroyedSockets, 1);
7662
});
7763
const server = https.createServer(serverOptions, (req, res) => {
78-
socket = req.socket;
7964
requestCount++;
8065
});
81-
server.setTimeout(200, (socket) => {
82-
timeoutCount++;
66+
server.setTimeout(500, common.mustCall((socket) => {
67+
// End this test and call `run()` for the next test (if any).
8368
socket.destroy();
84-
});
69+
server.close();
70+
cb();
71+
}));
8572
server.keepAliveTimeout = 50;
8673
server.listen(0, common.mustCall(() => {
8774
const options = {
@@ -94,10 +81,5 @@ test(function serverNoEndKeepAliveTimeoutWithPipeline(cb) {
9481
c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n');
9582
c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n');
9683
});
97-
setTimeout(() => {
98-
server.close();
99-
if (socket && socket.destroyed) destroyedSockets++;
100-
cb();
101-
}, 1000);
10284
}));
10385
});

0 commit comments

Comments
 (0)