From f45793cce91cfac9e3bc58bbebd8b2ce4e77f120 Mon Sep 17 00:00:00 2001 From: Adrian Estrada Date: Fri, 30 Dec 2016 09:28:33 -0500 Subject: [PATCH] test: improve test-http-allow-req-after-204-res MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * use const instead of var * use common.mustCall to control functions execution * use assert.strictEqual instead of assert.equal * use arrow functions PR-URL: https://github.com/nodejs/node/pull/10503 Reviewed-By: Colin Ihrig Reviewed-By: Michaƫl Zasso Reviewed-By: Italo A. Casas Reviewed-By: James M Snell Reviewed-By: Prince John Wesley Reviewed-By: Luigi Pinca --- .../test-http-allow-req-after-204-res.js | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/test/parallel/test-http-allow-req-after-204-res.js b/test/parallel/test-http-allow-req-after-204-res.js index 1c94d815811388..e2243400fcc5bb 100644 --- a/test/parallel/test-http-allow-req-after-204-res.js +++ b/test/parallel/test-http-allow-req-after-204-res.js @@ -1,35 +1,32 @@ 'use strict'; -require('../common'); -var http = require('http'); -var assert = require('assert'); +const common = require('../common'); +const http = require('http'); +const assert = require('assert'); // first 204 or 304 works, subsequent anything fails -var codes = [204, 200]; +const codes = [204, 200]; // Methods don't really matter, but we put in something realistic. -var methods = ['DELETE', 'DELETE']; +const methods = ['DELETE', 'DELETE']; -var server = http.createServer(function(req, res) { - var code = codes.shift(); - assert.equal('number', typeof code); +const server = http.createServer(common.mustCall((req, res) => { + const code = codes.shift(); + assert.strictEqual(typeof code, 'number'); assert.ok(code > 0); - console.error('writing %d response', code); res.writeHead(code, {}); res.end(); -}); +}, codes.length)); function nextRequest() { - var method = methods.shift(); - console.error('writing request: %s', method); + const method = methods.shift(); - var request = http.request({ + const request = http.request({ port: server.address().port, method: method, path: '/' - }, function(response) { - response.on('end', function() { + }, common.mustCall((response) => { + response.on('end', common.mustCall(() => { if (methods.length === 0) { - console.error('close server'); server.close(); } else { // throws error: @@ -37,9 +34,9 @@ function nextRequest() { // works just fine: //process.nextTick(nextRequest); } - }); + })); response.resume(); - }); + })); request.end(); }