Skip to content

Commit d00df5d

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 323ffac commit d00df5d

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+
returnthis[kLimit];
2021
}
2122

2223
getremaining(){

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
constcommon=require('../common');
2424
consthttp=require('http');
2525
constassert=require('assert');
26+
constCountdown=require('../common/countdown');
2627

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

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

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

4141
functionnextRequest(){
42-
constmethod=methods.shift();
4342

44-
constrequest=http.request({
43+
constrequest=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)