aboutsummaryrefslogtreecommitdiff
path: root/test/parallel/test-http-keep-alive.js
diff options
context:
space:
mode:
authorAdrian Estrada <edsadr@gmail.com>2016-12-20 19:00:10 -0500
committerItalo A. Casas <me@italoacasas.com>2016-12-21 20:43:12 -0500
commit1e98ea3f5e69a488edd9be76242ebb6b04033910 (patch)
treed697097d76169e463b068b5f557b3d24ddd42640 /test/parallel/test-http-keep-alive.js
parentdd9864928a29af8f3274c0244af4e53ae8f1ba60 (diff)
downloadandroid-node-v8-1e98ea3f5e69a488edd9be76242ebb6b04033910.tar.gz
android-node-v8-1e98ea3f5e69a488edd9be76242ebb6b04033910.tar.bz2
android-node-v8-1e98ea3f5e69a488edd9be76242ebb6b04033910.zip
test: refactor the code in test-http-keep-alive
* use common.mustCall to control the functions execution automatically * use let and const instead of var * use assert.strictEqual instead assert.equal PR-URL: https://github.com/nodejs/node/pull/10350 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Italo A. Casas <me@italoacasas.com>
Diffstat (limited to 'test/parallel/test-http-keep-alive.js')
-rw-r--r--test/parallel/test-http-keep-alive.js50
1 files changed, 25 insertions, 25 deletions
diff --git a/test/parallel/test-http-keep-alive.js b/test/parallel/test-http-keep-alive.js
index d48732e116..7f12e45765 100644
--- a/test/parallel/test-http-keep-alive.js
+++ b/test/parallel/test-http-keep-alive.js
@@ -1,51 +1,51 @@
'use strict';
-require('../common');
-var assert = require('assert');
-var http = require('http');
+const common = require('../common');
+const assert = require('assert');
+const http = require('http');
-var body = 'hello world\n';
+const server = http.createServer(common.mustCall((req, res) => {
+ const body = 'hello world\n';
-var server = http.createServer(function(req, res) {
res.writeHead(200, {'Content-Length': body.length});
res.write(body);
res.end();
-});
+}, 3));
-var agent = new http.Agent({maxSockets: 1});
-var headers = {'connection': 'keep-alive'};
-var name;
+const agent = new http.Agent({maxSockets: 1});
+const headers = {'connection': 'keep-alive'};
+let name;
-server.listen(0, function() {
+server.listen(0, common.mustCall(function() {
name = agent.getName({ port: this.address().port });
http.get({
path: '/', headers: headers, port: this.address().port, agent: agent
- }, function(response) {
- assert.equal(agent.sockets[name].length, 1);
- assert.equal(agent.requests[name].length, 2);
+ }, common.mustCall((response) => {
+ assert.strictEqual(agent.sockets[name].length, 1);
+ assert.strictEqual(agent.requests[name].length, 2);
response.resume();
- });
+ }));
http.get({
path: '/', headers: headers, port: this.address().port, agent: agent
- }, function(response) {
- assert.equal(agent.sockets[name].length, 1);
- assert.equal(agent.requests[name].length, 1);
+ }, common.mustCall((response) => {
+ assert.strictEqual(agent.sockets[name].length, 1);
+ assert.strictEqual(agent.requests[name].length, 1);
response.resume();
- });
+ }));
http.get({
path: '/', headers: headers, port: this.address().port, agent: agent
- }, function(response) {
- response.on('end', function() {
- assert.equal(agent.sockets[name].length, 1);
+ }, common.mustCall((response) => {
+ response.on('end', common.mustCall(() => {
+ assert.strictEqual(agent.sockets[name].length, 1);
assert(!agent.requests.hasOwnProperty(name));
server.close();
- });
+ }));
response.resume();
- });
-});
+ }));
+}));
-process.on('exit', function() {
+process.on('exit', () => {
assert(!agent.sockets.hasOwnProperty(name));
assert(!agent.requests.hasOwnProperty(name));
});