Skip to content

Commit 42454a5

Browse files
mithunsasidharangibfahn
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 3ee4c1e commit 42454a5

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

test/common/countdown.js

Lines changed: 1 addition & 0 deletions
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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
const common = require('../common');
33
const http = require('http');
44
const assert = require('assert');
5+
const Countdown = require('../common/countdown');
56

67
// first 204 or 304 works, subsequent anything fails
78
const codes = [204, 200];
89

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

1212
const server = http.createServer(common.mustCall((req, res) => {
1313
const code = codes.shift();
@@ -18,17 +18,13 @@ const server = http.createServer(common.mustCall((req, res) => {
1818
}, codes.length));
1919

2020
function nextRequest() {
21-
const method = methods.shift();
2221

23-
const request = http.request({
22+
const request = http.get({
2423
port: server.address().port,
25-
method: method,
2624
path: '/'
2725
}, common.mustCall((response) => {
2826
response.on('end', common.mustCall(() => {
29-
if (methods.length === 0) {
30-
server.close();
31-
} else {
27+
if (countdown.dec()) {
3228
// throws error:
3329
nextRequest();
3430
// works just fine:

0 commit comments

Comments
 (0)