Skip to content

Commit

Permalink
test: refactored test-http-allow-req-after-204-res to countdown
Browse files Browse the repository at this point in the history
PR-URL: #17211
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
  • Loading branch information
mithunsasidharan authored and MylesBorins committed Dec 12, 2017
1 parent ef25de7 commit 4fb0708
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
1 change: 1 addition & 0 deletions test/common/countdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Countdown {
assert(this[kLimit] > 0, 'Countdown expired');
if (--this[kLimit] === 0)
this[kCallback]();
return this[kLimit];
}

get remaining() {
Expand Down
12 changes: 4 additions & 8 deletions test/parallel/test-http-allow-req-after-204-res.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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:
Expand Down

0 comments on commit 4fb0708

Please sign in to comment.