Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored test-http-allow-req-after-204-res file to use countdown #17211

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong opinion, but instead of modifying common/countdown.js, you can just use the existing API and do something like

countdown.dec();
if (countdown.remaining > 0) {
  ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aqrln : I feel making the change in countdown.jswill be better as it makes the test case condition more readable and save an extra line! Kindly suggest. Also, could you please run the CI. I've fixed the lint issues. Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mithunsasidharan sure, no problem. In the future, please run make -j4 test locally before pushing to the PR branch to save your time and the number of review iterations. Thanks!

// throws error:
nextRequest();
// works just fine:
Expand Down