Skip to content

Commit 4fb0708

Browse files
mithunsasidharanMylesBorins
authored andcommitted
test: refactored test-http-allow-req-after-204-res to countdown
PR-URL: #17211 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Alexey Orlenko <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
1 parent ef25de7 commit 4fb0708

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

test/common/countdown.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Countdown {
1717
assert(this[kLimit] > 0, 'Countdown expired');
1818
if (--this[kLimit] === 0)
1919
this[kCallback]();
20+
return this[kLimit];
2021
}
2122

2223
get remaining() {

test/parallel/test-http-allow-req-after-204-res.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
const common = require('../common');
2424
const http = require('http');
2525
const assert = require('assert');
26+
const Countdown = require('../common/countdown');
2627

2728
// first 204 or 304 works, subsequent anything fails
2829
const codes = [204, 200];
2930

30-
// Methods don't really matter, but we put in something realistic.
31-
const methods = ['DELETE', 'DELETE'];
31+
const countdown = new Countdown(codes.length, () => server.close());
3232

3333
const server = http.createServer(common.mustCall((req, res) => {
3434
const code = codes.shift();
@@ -39,17 +39,13 @@ const server = http.createServer(common.mustCall((req, res) => {
3939
}, codes.length));
4040

4141
function nextRequest() {
42-
const method = methods.shift();
4342

44-
const request = http.request({
43+
const request = http.get({
4544
port: server.address().port,
46-
method: method,
4745
path: '/'
4846
}, common.mustCall((response) => {
4947
response.on('end', common.mustCall(() => {
50-
if (methods.length === 0) {
51-
server.close();
52-
} else {
48+
if (countdown.dec()) {
5349
// throws error:
5450
nextRequest();
5551
// works just fine:

0 commit comments

Comments
 (0)