From 9c9d422433642df6455999a458af122e5fcc2c13 Mon Sep 17 00:00:00 2001 From: larissayvette Date: Sun, 11 Dec 2016 12:12:46 +0100 Subject: [PATCH] test: refactor test-http-after-connect.js - Replace assert.equal() to assert.strictEqual() - Replace var with const where applicable - Removed firstBodyChunk which is never used - Remove the process.on('exit', ...) and replace its functionality by - Using common.mustCall() where applicable PR-URL: https://github.com/nodejs/node/pull/10229 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Italo A. Casas Reviewed-By: Colin Ihrig Reviewed-By: Rich Trott --- test/parallel/test-http-after-connect.js | 36 +++++++++--------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/test/parallel/test-http-after-connect.js b/test/parallel/test-http-after-connect.js index 0bae99b1d34cf1..0580f428ed70f5 100644 --- a/test/parallel/test-http-after-connect.js +++ b/test/parallel/test-http-after-connect.js @@ -1,38 +1,34 @@ '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 serverConnected = false; -var serverRequests = 0; var clientResponses = 0; -var server = http.createServer(function(req, res) { +const server = http.createServer(common.mustCall(function(req, res) { console.error('Server got GET request'); req.resume(); - ++serverRequests; res.writeHead(200); res.write(''); setTimeout(function() { res.end(req.url); }, 50); -}); -server.on('connect', function(req, socket, firstBodyChunk) { +}, 2)); +server.on('connect', common.mustCall(function(req, socket) { console.error('Server got CONNECT request'); - serverConnected = true; socket.write('HTTP/1.1 200 Connection established\r\n\r\n'); socket.resume(); socket.on('end', function() { socket.end(); }); -}); +})); server.listen(0, function() { - var req = http.request({ + const req = http.request({ port: this.address().port, method: 'CONNECT', path: 'google.com:80' }); - req.on('connect', function(res, socket, firstBodyChunk) { + req.on('connect', common.mustCall(function(res, socket) { console.error('Client got CONNECT response'); socket.end(); socket.on('end', function() { @@ -40,7 +36,7 @@ server.listen(0, function() { doRequest(1); }); socket.resume(); - }); + })); req.end(); }); @@ -48,7 +44,7 @@ function doRequest(i) { http.get({ port: server.address().port, path: '/request' + i - }, function(res) { + }, common.mustCall(function(res) { console.error('Client got GET response'); var data = ''; res.setEncoding('utf8'); @@ -56,17 +52,11 @@ function doRequest(i) { data += chunk; }); res.on('end', function() { - assert.equal(data, '/request' + i); + assert.strictEqual(data, '/request' + i); ++clientResponses; if (clientResponses === 2) { server.close(); } }); - }); + })); } - -process.on('exit', function() { - assert(serverConnected); - assert.equal(serverRequests, 2); - assert.equal(clientResponses, 2); -});