From f6926d5d002273100a24a33a05ceb000eaae9fbe Mon Sep 17 00:00:00 2001 From: Mithun Sasidharan Date: Tue, 28 Nov 2017 12:10:28 +0530 Subject: [PATCH] test: refactored test-http-allow-req-after-204-res to countdown PR-URL: https://github.com/nodejs/node/pull/17211 Reviewed-By: James M Snell Reviewed-By: Alexey Orlenko Reviewed-By: Sakthipriyan Vairamani --- test/common/countdown.js | 1 + test/parallel/test-http-allow-req-after-204-res.js | 12 ++++-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/test/common/countdown.js b/test/common/countdown.js index 6a22be0a07eb0b..93bdbbfb16da5d 100644 --- a/test/common/countdown.js +++ b/test/common/countdown.js @@ -17,6 +17,7 @@ class Countdown { assert(this[kLimit] > 0, 'Countdown expired'); if (--this[kLimit] === 0) this[kCallback](); + return this[kLimit]; } get remaining() { 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 cd55a4f17c2b1e..8de53a9e539a66 100644 --- a/test/parallel/test-http-allow-req-after-204-res.js +++ b/test/parallel/test-http-allow-req-after-204-res.js @@ -23,12 +23,12 @@ const common = require('../common'); const http = require('http'); const assert = require('assert'); +const Countdown = require('../common/countdown'); // first 204 or 304 works, subsequent anything fails const codes = [204, 200]; -// Methods don't really matter, but we put in something realistic. -const methods = ['DELETE', 'DELETE']; +const countdown = new Countdown(codes.length, () => server.close()); const server = http.createServer(common.mustCall((req, res) => { const code = codes.shift(); @@ -39,17 +39,13 @@ const server = http.createServer(common.mustCall((req, res) => { }, codes.length)); function nextRequest() { - const method = methods.shift(); - const request = http.request({ + const request = http.get({ port: server.address().port, - method: method, path: '/' }, common.mustCall((response) => { response.on('end', common.mustCall(() => { - if (methods.length === 0) { - server.close(); - } else { + if (countdown.dec()) { // throws error: nextRequest(); // works just fine: