diff options
author | James M Snell <jasnell@gmail.com> | 2017-07-14 15:05:24 -0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2017-07-24 14:16:49 -0700 |
commit | b0a8a7c6baccea746da10e01bfb3dec18c0d723e (patch) | |
tree | 3bdf54ff6e3daa9c6ac9816914c7a51b892021dd /test/parallel/test-http-agent-error-on-idle.js | |
parent | ed21cb1774d3e146f84a94400db0008a940656c3 (diff) | |
download | android-node-v8-b0a8a7c6baccea746da10e01bfb3dec18c0d723e.tar.gz android-node-v8-b0a8a7c6baccea746da10e01bfb3dec18c0d723e.tar.bz2 android-node-v8-b0a8a7c6baccea746da10e01bfb3dec18c0d723e.zip |
test: improvements to various http tests
* Add common/countdown utility
* Numerous improvements to http tests
PR-URL: https://github.com/nodejs/node/pull/14315
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'test/parallel/test-http-agent-error-on-idle.js')
-rw-r--r-- | test/parallel/test-http-agent-error-on-idle.js | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/test/parallel/test-http-agent-error-on-idle.js b/test/parallel/test-http-agent-error-on-idle.js index 2f270c0d30..fce5e8f032 100644 --- a/test/parallel/test-http-agent-error-on-idle.js +++ b/test/parallel/test-http-agent-error-on-idle.js @@ -1,32 +1,31 @@ 'use strict'; -require('../common'); + +const common = require('../common'); const assert = require('assert'); const http = require('http'); const Agent = http.Agent; -const server = http.createServer(function(req, res) { +const server = http.createServer(common.mustCall((req, res) => { res.end('hello world'); -}); +}, 2)); -server.listen(0, function() { - const agent = new Agent({ - keepAlive: true, - }); +server.listen(0, () => { + const agent = new Agent({ keepAlive: true }); const requestParams = { host: 'localhost', - port: this.address().port, + port: server.address().port, agent: agent, path: '/' }; const socketKey = agent.getName(requestParams); - get(function(res) { + http.get(requestParams, common.mustCall((res) => { assert.strictEqual(res.statusCode, 200); res.resume(); - res.on('end', function() { - process.nextTick(function() { + res.on('end', common.mustCall(() => { + process.nextTick(common.mustCall(() => { const freeSockets = agent.freeSockets[socketKey]; assert.strictEqual(freeSockets.length, 1, `expect a free socket on ${socketKey}`); @@ -35,14 +34,10 @@ server.listen(0, function() { const freeSocket = freeSockets[0]; freeSocket.emit('error', new Error('ECONNRESET: test')); - get(done); - }); - }); - }); - - function get(callback) { - return http.get(requestParams, callback); - } + http.get(requestParams, done); + })); + })); + })); function done() { assert.strictEqual(Object.keys(agent.freeSockets).length, 0, @@ -50,6 +45,5 @@ server.listen(0, function() { agent.destroy(); server.close(); - process.exit(0); } }); |