summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-should-keep-alive.js
diff options
context:
space:
mode:
authorTomerOmri <tomer92@gmail.com>2017-12-06 21:13:37 +0200
committerJon Moss <me@jonathanmoss.me>2017-12-09 12:41:50 -0500
commite9d1e1265a8d8aa708ae2a57088e43d08c81415e (patch)
tree85b2c38deb2ef81ce483953d95ba2d761ab3eb4b /test/parallel/test-http-should-keep-alive.js
parentea77b33a526763675713dbc23cbd7fa98f733f27 (diff)
downloadandroid-node-v8-e9d1e1265a8d8aa708ae2a57088e43d08c81415e.tar.gz
android-node-v8-e9d1e1265a8d8aa708ae2a57088e43d08c81415e.tar.bz2
android-node-v8-e9d1e1265a8d8aa708ae2a57088e43d08c81415e.zip
test: update test-http-should-keep-alive to use countdown
PR-URL: https://github.com/nodejs/node/pull/17505 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Jon Moss <me@jonathanmoss.me>
Diffstat (limited to 'test/parallel/test-http-should-keep-alive.js')
-rw-r--r--test/parallel/test-http-should-keep-alive.js28
1 files changed, 11 insertions, 17 deletions
diff --git a/test/parallel/test-http-should-keep-alive.js b/test/parallel/test-http-should-keep-alive.js
index dd4709d694..038af47ee4 100644
--- a/test/parallel/test-http-should-keep-alive.js
+++ b/test/parallel/test-http-should-keep-alive.js
@@ -24,6 +24,7 @@ require('../common');
const assert = require('assert');
const http = require('http');
const net = require('net');
+const Countdown = require('../common/countdown');
const SERVER_RESPONSES = [
'HTTP/1.0 200 ok\r\nContent-Length: 0\r\n\r\n',
@@ -41,34 +42,27 @@ const SHOULD_KEEP_ALIVE = [
true, // HTTP/1.1, Connection: keep-alive
false // HTTP/1.1, Connection: close
];
-let requests = 0;
-let responses = 0;
http.globalAgent.maxSockets = 5;
+const countdown = new Countdown(SHOULD_KEEP_ALIVE.length, () => server.close());
+
+const getCountdownIndex = () => SERVER_RESPONSES.length - countdown.remaining;
+
const server = net.createServer(function(socket) {
- socket.write(SERVER_RESPONSES[requests]);
- ++requests;
+ socket.write(SERVER_RESPONSES[getCountdownIndex()]);
}).listen(0, function() {
function makeRequest() {
const req = http.get({ port: server.address().port }, function(res) {
assert.strictEqual(
- req.shouldKeepAlive, SHOULD_KEEP_ALIVE[responses],
- `${SERVER_RESPONSES[responses]} should ${
- SHOULD_KEEP_ALIVE[responses] ? '' : 'not '}Keep-Alive`);
- ++responses;
- if (responses < SHOULD_KEEP_ALIVE.length) {
+ req.shouldKeepAlive, SHOULD_KEEP_ALIVE[getCountdownIndex()],
+ `${SERVER_RESPONSES[getCountdownIndex()]} should ${
+ SHOULD_KEEP_ALIVE[getCountdownIndex()] ? '' : 'not '}Keep-Alive`);
+ countdown.dec();
+ if (countdown.remaining) {
makeRequest();
- } else {
- server.close();
}
res.resume();
});
}
-
makeRequest();
});
-
-process.on('exit', function() {
- assert.strictEqual(requests, SERVER_RESPONSES.length);
- assert.strictEqual(responses, SHOULD_KEEP_ALIVE.length);
-});