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 <jasnell@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
This commit is contained in:
parent
fa072499a5
commit
f6926d5d00
@ -17,6 +17,7 @@ class Countdown {
|
|||||||
assert(this[kLimit] > 0, 'Countdown expired');
|
assert(this[kLimit] > 0, 'Countdown expired');
|
||||||
if (--this[kLimit] === 0)
|
if (--this[kLimit] === 0)
|
||||||
this[kCallback]();
|
this[kCallback]();
|
||||||
|
return this[kLimit];
|
||||||
}
|
}
|
||||||
|
|
||||||
get remaining() {
|
get remaining() {
|
||||||
|
@ -23,12 +23,12 @@
|
|||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
const Countdown = require('../common/countdown');
|
||||||
|
|
||||||
// first 204 or 304 works, subsequent anything fails
|
// first 204 or 304 works, subsequent anything fails
|
||||||
const codes = [204, 200];
|
const codes = [204, 200];
|
||||||
|
|
||||||
// Methods don't really matter, but we put in something realistic.
|
const countdown = new Countdown(codes.length, () => server.close());
|
||||||
const methods = ['DELETE', 'DELETE'];
|
|
||||||
|
|
||||||
const server = http.createServer(common.mustCall((req, res) => {
|
const server = http.createServer(common.mustCall((req, res) => {
|
||||||
const code = codes.shift();
|
const code = codes.shift();
|
||||||
@ -39,17 +39,13 @@ const server = http.createServer(common.mustCall((req, res) => {
|
|||||||
}, codes.length));
|
}, codes.length));
|
||||||
|
|
||||||
function nextRequest() {
|
function nextRequest() {
|
||||||
const method = methods.shift();
|
|
||||||
|
|
||||||
const request = http.request({
|
const request = http.get({
|
||||||
port: server.address().port,
|
port: server.address().port,
|
||||||
method: method,
|
|
||||||
path: '/'
|
path: '/'
|
||||||
}, common.mustCall((response) => {
|
}, common.mustCall((response) => {
|
||||||
response.on('end', common.mustCall(() => {
|
response.on('end', common.mustCall(() => {
|
||||||
if (methods.length === 0) {
|
if (countdown.dec()) {
|
||||||
server.close();
|
|
||||||
} else {
|
|
||||||
// throws error:
|
// throws error:
|
||||||
nextRequest();
|
nextRequest();
|
||||||
// works just fine:
|
// works just fine:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user