|
@ -1,26 +1,26 @@ |
|
|
'use strict'; |
|
|
'use strict'; |
|
|
var common = require('../common'); |
|
|
const common = require('../common'); |
|
|
var assert = require('assert'); |
|
|
const assert = require('assert'); |
|
|
var http = require('http'); |
|
|
const http = require('http'); |
|
|
var Agent = require('_http_agent').Agent; |
|
|
const Agent = require('_http_agent').Agent; |
|
|
|
|
|
|
|
|
var agent = new Agent({ |
|
|
const agent = new Agent({ |
|
|
keepAlive: true, |
|
|
keepAlive: true, |
|
|
keepAliveMsecs: 1000, |
|
|
keepAliveMsecs: 1000, |
|
|
maxSockets: 5, |
|
|
maxSockets: 5, |
|
|
maxFreeSockets: 5 |
|
|
maxFreeSockets: 5 |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
var server = http.createServer(function(req, res) { |
|
|
const server = http.createServer(function(req, res) { |
|
|
if (req.url === '/error') { |
|
|
if (req.url === '/error') { |
|
|
res.destroy(); |
|
|
res.destroy(); |
|
|
return; |
|
|
return; |
|
|
} else if (req.url === '/remote_close') { |
|
|
} else if (req.url === '/remote_close') { |
|
|
// cache the socket, close it after 100ms
|
|
|
// cache the socket, close it after a short delay
|
|
|
var socket = res.connection; |
|
|
const socket = res.connection; |
|
|
setTimeout(function() { |
|
|
setImmediate(function() { |
|
|
socket.end(); |
|
|
socket.end(); |
|
|
}, 100); |
|
|
}); |
|
|
} |
|
|
} |
|
|
res.end('hello world'); |
|
|
res.end('hello world'); |
|
|
}); |
|
|
}); |
|
@ -34,7 +34,7 @@ function get(path, callback) { |
|
|
}, callback); |
|
|
}, callback); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var name = 'localhost:' + common.PORT + ':'; |
|
|
const name = 'localhost:' + common.PORT + ':'; |
|
|
|
|
|
|
|
|
function checkDataAndSockets(body) { |
|
|
function checkDataAndSockets(body) { |
|
|
assert.equal(body.toString(), 'hello world'); |
|
|
assert.equal(body.toString(), 'hello world'); |
|
@ -76,7 +76,7 @@ function remoteClose() { |
|
|
assert.equal(agent.freeSockets[name], undefined, |
|
|
assert.equal(agent.freeSockets[name], undefined, |
|
|
'freeSockets is not empty'); |
|
|
'freeSockets is not empty'); |
|
|
remoteError(); |
|
|
remoteError(); |
|
|
}, 200); |
|
|
}, common.platformTimeout(200)); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
@ -84,7 +84,7 @@ function remoteClose() { |
|
|
|
|
|
|
|
|
function remoteError() { |
|
|
function remoteError() { |
|
|
// remove server will destroy ths socket
|
|
|
// remove server will destroy ths socket
|
|
|
var req = get('/error', function(res) { |
|
|
const req = get('/error', function(res) { |
|
|
throw new Error('should not call this function'); |
|
|
throw new Error('should not call this function'); |
|
|
}); |
|
|
}); |
|
|
req.on('error', function(err) { |
|
|
req.on('error', function(err) { |
|
@ -97,7 +97,7 @@ function remoteError() { |
|
|
assert.equal(agent.sockets[name], undefined); |
|
|
assert.equal(agent.sockets[name], undefined); |
|
|
assert.equal(agent.freeSockets[name], undefined); |
|
|
assert.equal(agent.freeSockets[name], undefined); |
|
|
done(); |
|
|
done(); |
|
|
}, 1); |
|
|
}, common.platformTimeout(1)); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|