Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6576382

Browse filesBrowse files
tomeromrixMylesBorins
authored andcommitted
test: update test-http-should-keep-alive to use countdown
PR-URL: #17505 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Jon Moss <me@jonathanmoss.me>
1 parent 70cfe68 commit 6576382
Copy full SHA for 6576382

File tree

Expand file treeCollapse file tree

1 file changed

+11
-17
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+11
-17
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-http-should-keep-alive.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http-should-keep-alive.js
+11-17Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ require('../common');
2424
const assert = require('assert');
2525
const http = require('http');
2626
const net = require('net');
27+
const Countdown = require('../common/countdown');
2728

2829
const SERVER_RESPONSES = [
2930
'HTTP/1.0 200 ok\r\nContent-Length: 0\r\n\r\n',
@@ -41,34 +42,27 @@ const SHOULD_KEEP_ALIVE = [
4142
true, // HTTP/1.1, Connection: keep-alive
4243
false // HTTP/1.1, Connection: close
4344
];
44-
let requests = 0;
45-
let responses = 0;
4645
http.globalAgent.maxSockets = 5;
4746

47+
const countdown = new Countdown(SHOULD_KEEP_ALIVE.length, () => server.close());
48+
49+
const getCountdownIndex = () => SERVER_RESPONSES.length - countdown.remaining;
50+
4851
const server = net.createServer(function(socket) {
49-
socket.write(SERVER_RESPONSES[requests]);
50-
++requests;
52+
socket.write(SERVER_RESPONSES[getCountdownIndex()]);
5153
}).listen(0, function() {
5254
function makeRequest() {
5355
const req = http.get({ port: server.address().port }, function(res) {
5456
assert.strictEqual(
55-
req.shouldKeepAlive, SHOULD_KEEP_ALIVE[responses],
56-
`${SERVER_RESPONSES[responses]} should ${
57-
SHOULD_KEEP_ALIVE[responses] ? '' : 'not '}Keep-Alive`);
58-
++responses;
59-
if (responses < SHOULD_KEEP_ALIVE.length) {
57+
req.shouldKeepAlive, SHOULD_KEEP_ALIVE[getCountdownIndex()],
58+
`${SERVER_RESPONSES[getCountdownIndex()]} should ${
59+
SHOULD_KEEP_ALIVE[getCountdownIndex()] ? '' : 'not '}Keep-Alive`);
60+
countdown.dec();
61+
if (countdown.remaining) {
6062
makeRequest();
61-
} else {
62-
server.close();
6363
}
6464
res.resume();
6565
});
6666
}
67-
6867
makeRequest();
6968
});
70-
71-
process.on('exit', function() {
72-
assert.strictEqual(requests, SERVER_RESPONSES.length);
73-
assert.strictEqual(responses, SHOULD_KEEP_ALIVE.length);
74-
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.