mirror of https://github.com/lukechilds/node.git
Browse Source
* 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>v4.x
Adrian Estrada
8 years ago
committed by
Myles Borins
1 changed files with 25 additions and 25 deletions
@ -1,51 +1,51 @@ |
|||||
'use strict'; |
'use strict'; |
||||
require('../common'); |
const common = require('../common'); |
||||
var assert = require('assert'); |
const assert = require('assert'); |
||||
var http = require('http'); |
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.writeHead(200, {'Content-Length': body.length}); |
||||
res.write(body); |
res.write(body); |
||||
res.end(); |
res.end(); |
||||
}); |
}, 3)); |
||||
|
|
||||
var agent = new http.Agent({maxSockets: 1}); |
const agent = new http.Agent({maxSockets: 1}); |
||||
var headers = {'connection': 'keep-alive'}; |
const headers = {'connection': 'keep-alive'}; |
||||
var name; |
let name; |
||||
|
|
||||
server.listen(0, function() { |
server.listen(0, common.mustCall(function() { |
||||
name = agent.getName({ port: this.address().port }); |
name = agent.getName({ port: this.address().port }); |
||||
http.get({ |
http.get({ |
||||
path: '/', headers: headers, port: this.address().port, agent: agent |
path: '/', headers: headers, port: this.address().port, agent: agent |
||||
}, function(response) { |
}, common.mustCall((response) => { |
||||
assert.equal(agent.sockets[name].length, 1); |
assert.strictEqual(agent.sockets[name].length, 1); |
||||
assert.equal(agent.requests[name].length, 2); |
assert.strictEqual(agent.requests[name].length, 2); |
||||
response.resume(); |
response.resume(); |
||||
}); |
})); |
||||
|
|
||||
http.get({ |
http.get({ |
||||
path: '/', headers: headers, port: this.address().port, agent: agent |
path: '/', headers: headers, port: this.address().port, agent: agent |
||||
}, function(response) { |
}, common.mustCall((response) => { |
||||
assert.equal(agent.sockets[name].length, 1); |
assert.strictEqual(agent.sockets[name].length, 1); |
||||
assert.equal(agent.requests[name].length, 1); |
assert.strictEqual(agent.requests[name].length, 1); |
||||
response.resume(); |
response.resume(); |
||||
}); |
})); |
||||
|
|
||||
http.get({ |
http.get({ |
||||
path: '/', headers: headers, port: this.address().port, agent: agent |
path: '/', headers: headers, port: this.address().port, agent: agent |
||||
}, function(response) { |
}, common.mustCall((response) => { |
||||
response.on('end', function() { |
response.on('end', common.mustCall(() => { |
||||
assert.equal(agent.sockets[name].length, 1); |
assert.strictEqual(agent.sockets[name].length, 1); |
||||
assert(!agent.requests.hasOwnProperty(name)); |
assert(!agent.requests.hasOwnProperty(name)); |
||||
server.close(); |
server.close(); |
||||
}); |
})); |
||||
response.resume(); |
response.resume(); |
||||
}); |
})); |
||||
}); |
})); |
||||
|
|
||||
process.on('exit', function() { |
process.on('exit', () => { |
||||
assert(!agent.sockets.hasOwnProperty(name)); |
assert(!agent.sockets.hasOwnProperty(name)); |
||||
assert(!agent.requests.hasOwnProperty(name)); |
assert(!agent.requests.hasOwnProperty(name)); |
||||
}); |
}); |
||||
|
Loading…
Reference in new issue