From a852d3c8cf09ad39502ee1e35d55c621455f47d5 Mon Sep 17 00:00:00 2001 From: Canastro Date: Sat, 17 Sep 2016 10:57:08 +0200 Subject: [PATCH 1/2] test: cleanup test-http-agent-destroyed-socket --- .../test-http-agent-destroyed-socket.js | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/test/parallel/test-http-agent-destroyed-socket.js b/test/parallel/test-http-agent-destroyed-socket.js index 34772f7d3e3081..96edec56b3f4df 100644 --- a/test/parallel/test-http-agent-destroyed-socket.js +++ b/test/parallel/test-http-agent-destroyed-socket.js @@ -1,35 +1,35 @@ 'use strict'; require('../common'); -var assert = require('assert'); -var http = require('http'); +const assert = require('assert'); +const http = require('http'); -var server = http.createServer(function(req, res) { +const server = http.createServer((req, res) => { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(0, function() { - var agent = new http.Agent({maxSockets: 1}); + const agent = new http.Agent({maxSockets: 1}); - agent.on('free', function(socket, host, port) { + agent.on('free', (socket, host, port) => { console.log('freeing socket. destroyed? ', socket.destroyed); }); - var requestOptions = { + const requestOptions = { agent: agent, host: 'localhost', port: this.address().port, path: '/' }; - var request1 = http.get(requestOptions, function(response) { + const request1 = http.get(requestOptions, (response) => { // assert request2 is queued in the agent - var key = agent.getName(requestOptions); - assert(agent.requests[key].length === 1); + const key = agent.getName(requestOptions); + assert.strictEqual(agent.requests[key].length, 1); console.log('got response1'); - request1.socket.on('close', function() { + request1.socket.on('close', () => { console.log('request1 socket closed'); }); response.pipe(process.stdout); - response.on('end', function() { + response.on('end', () => { console.log('response1 done'); ///////////////////////////////// // @@ -44,35 +44,35 @@ var server = http.createServer(function(req, res) { // is triggered. request1.socket.destroy(); - response.once('close', function() { + response.once('close', () => { // assert request2 was removed from the queue assert(!agent.requests[key]); console.log("waiting for request2.onSocket's nextTick"); - process.nextTick(function() { + process.nextTick(() => { // assert that the same socket was not assigned to request2, // since it was destroyed. - assert(request1.socket !== request2.socket); + assert.notStrictEqual(request1.socket, request2.socket); assert(!request2.socket.destroyed, 'the socket is destroyed'); }); }); }); }); - var request2 = http.get(requestOptions, function(response) { + const request2 = http.get(requestOptions, (response) => { assert(!request2.socket.destroyed); assert(request1.socket.destroyed); // assert not reusing the same socket, since it was destroyed. - assert(request1.socket !== request2.socket); + assert.notStrictEqual(request1.socket, request2.socket); console.log('got response2'); - var gotClose = false; - var gotResponseEnd = false; - request2.socket.on('close', function() { + let gotClose = false; + let gotResponseEnd = false; + request2.socket.on('close', () => { console.log('request2 socket closed'); gotClose = true; done(); }); response.pipe(process.stdout); - response.on('end', function() { + response.on('end', () => { console.log('response2 done'); gotResponseEnd = true; done(); From b230d07ab037b6462263bc60f74cb9aa508c0a53 Mon Sep 17 00:00:00 2001 From: Canastro Date: Sat, 17 Sep 2016 11:22:07 +0200 Subject: [PATCH 2/2] temp commit --- .../test-http-agent-destroyed-socket.js | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/parallel/test-http-agent-destroyed-socket.js b/test/parallel/test-http-agent-destroyed-socket.js index 96edec56b3f4df..6c714fa235a050 100644 --- a/test/parallel/test-http-agent-destroyed-socket.js +++ b/test/parallel/test-http-agent-destroyed-socket.js @@ -1,5 +1,5 @@ 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const http = require('http'); @@ -20,7 +20,7 @@ const server = http.createServer((req, res) => { path: '/' }; - const request1 = http.get(requestOptions, (response) => { + const request1 = http.get(requestOptions, common.mustCall((response) => { // assert request2 is queued in the agent const key = agent.getName(requestOptions); assert.strictEqual(agent.requests[key].length, 1); @@ -44,7 +44,7 @@ const server = http.createServer((req, res) => { // is triggered. request1.socket.destroy(); - response.once('close', () => { + response.once('close', common.mustCall(() => { // assert request2 was removed from the queue assert(!agent.requests[key]); console.log("waiting for request2.onSocket's nextTick"); @@ -54,11 +54,11 @@ const server = http.createServer((req, res) => { assert.notStrictEqual(request1.socket, request2.socket); assert(!request2.socket.destroyed, 'the socket is destroyed'); }); - }); + })); }); - }); + })); - const request2 = http.get(requestOptions, (response) => { + const request2 = http.get(requestOptions, common.mustCall((response) => { assert(!request2.socket.destroyed); assert(request1.socket.destroyed); // assert not reusing the same socket, since it was destroyed. @@ -66,21 +66,21 @@ const server = http.createServer((req, res) => { console.log('got response2'); let gotClose = false; let gotResponseEnd = false; - request2.socket.on('close', () => { + request2.socket.on('close', common.mustCall(() => { console.log('request2 socket closed'); gotClose = true; done(); - }); + })); response.pipe(process.stdout); - response.on('end', () => { + response.on('end', common.mustCall(() => { console.log('response2 done'); gotResponseEnd = true; done(); - }); + })); function done() { if (gotResponseEnd && gotClose) server.close(); } - }); + })); });