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

refac: refactor test-http-response-multiheaders.js test to use countdown #17419

Closed
Changes from 2 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
8 changes: 5 additions & 3 deletions test/parallel/test-http-response-multiheaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const common = require('../common');
const http = require('http');
const assert = require('assert');
const Countdown = require('../common/countdown');

// Test that certain response header fields do not repeat.
// 'content-length' should also be in this list but it is
Expand Down Expand Up @@ -47,8 +48,9 @@ const server = http.createServer(function(req, res) {
});

server.listen(0, common.mustCall(function() {
let count = 0;
for (let n = 1; n <= 2; n++) {
const runCount = 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move runCount to live outside of the server.listen?

Copy link
Author

Choose a reason for hiding this comment

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

@maclover7 like this afacc3e ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe so -- although the linter may want an extra blank line (you can check this via make lint-js :))

Copy link
Author

Choose a reason for hiding this comment

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

@maclover7 it says Running JS linter... and then exits. Does it mean that everything is ok? :)

Copy link
Contributor

Choose a reason for hiding this comment

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

@LEQADA Yep -- if no errors show up then all good. You can also see the linter CI job passing at https://ci.nodejs.org/job/node-test-linter/14156/

const countdown = new Countdown(runCount, () => server.close());
for (let n = 1; n <= runCount; n++) {
// this runs twice, the first time, the server will use
// setHeader, the second time it uses writeHead. The
// result on the client side should be the same in
Expand All @@ -58,7 +60,7 @@ server.listen(0, common.mustCall(function() {
http.get(
{ port: this.address().port, headers: { 'x-num': n } },
common.mustCall(function(res) {
if (++count === 2) server.close();
countdown.dec();
for (const name of norepeat) {
assert.strictEqual(res.headers[name], 'A');
}
Expand Down