From 565f0f73e28dc66167ea49f45430afaec7f2d1cb Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 25 Mar 2020 14:55:50 -0700 Subject: [PATCH] test: revise test-http-client-default-headers-exist * Remove assert.strictEqual where assert.ok suffices * Replace countdown with Promise.all() PR-URL: https://github.com/nodejs/node/pull/32493 Reviewed-By: James M Snell Reviewed-By: Anna Henningsen --- .../test-http-client-default-headers-exist.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/test/parallel/test-http-client-default-headers-exist.js b/test/parallel/test-http-client-default-headers-exist.js index ba4d4fa660b2cc..e19be4b7d70856 100644 --- a/test/parallel/test-http-client-default-headers-exist.js +++ b/test/parallel/test-http-client-default-headers-exist.js @@ -23,7 +23,8 @@ const common = require('../common'); const assert = require('assert'); const http = require('http'); -const Countdown = require('../common/countdown'); + +const { once } = require('events'); const expectedHeaders = { 'DELETE': ['host', 'connection'], @@ -37,10 +38,6 @@ const expectedHeaders = { const expectedMethods = Object.keys(expectedHeaders); -const countdown = - new Countdown(expectedMethods.length, - common.mustCall(() => server.close())); - const server = http.createServer(common.mustCall((req, res) => { res.end(); @@ -49,9 +46,8 @@ const server = http.createServer(common.mustCall((req, res) => { const requestHeaders = Object.keys(req.headers); requestHeaders.forEach((header) => { - assert.strictEqual( + assert.ok( expectedHeaders[req.method].includes(header.toLowerCase()), - true, `${header} should not exist for method ${req.method}` ); }); @@ -61,15 +57,14 @@ const server = http.createServer(common.mustCall((req, res) => { expectedHeaders[req.method].length, `some headers were missing for method: ${req.method}` ); - - countdown.dec(); }, expectedMethods.length)); server.listen(0, common.mustCall(() => { - expectedMethods.forEach((method) => { - http.request({ + Promise.all(expectedMethods.map(async (method) => { + const request = http.request({ method: method, port: server.address().port }).end(); - }); + return once(request, 'response'); + })).then(common.mustCall(() => { server.close(); })); }));