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

test: improve numerous http tests #12930

Closed
wants to merge 1 commit into from

Conversation

jasnell
Copy link
Member

@jasnell jasnell commented May 9, 2017

Minor refactoring in a number of http tests. I've been going through an auditing the existing http tests to identify which we will need equivalents for on the http2 implementation and spotted a number of cleanups that could be made.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

tests (http)

@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label May 9, 2017
* Use common.mustCall where appropriate
* Remove extraneous console output
* Misc cleanups
Copy link
Contributor

@cjihrig cjihrig left a comment

Choose a reason for hiding this comment

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

LGTM with the same nit throughout.

c.write(request_generator());
});
c.on('connect', common.mustCall(() => c.write(request_generator())));
c.on('data', common.mustCall((chunk) => server_response += chunk));
Copy link
Contributor

@cjihrig cjihrig May 9, 2017

Choose a reason for hiding this comment

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

I don't think we should add common.mustCall() around 'data' event handlers because they can be called a number of times.

Copy link
Member Author

Choose a reason for hiding this comment

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

The idea for me is that tests should be predictable, and that for each of these tests, the number of times an event like data would be called should be deterministic. If a change is made that changes that, then the test should pick up on it and update the test. Doing so would increase the visibility of such changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

common.mustCall() takes an expected:int as second argument.
I'll write a PR to have it expect '+' as "more than zero".

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with that point. But aren't we at the mercy of different platforms and whatnot for the flow of data? If it can be done reliably, and without platform specific checks, then 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

@Trott Trott May 9, 2017

Choose a reason for hiding this comment

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

Given that there's no way for the test to pass if the callback is not called (because server_response will not have the expected data), I would be inclined to drop common.mustCall(). The more layers of stuff added to the test, the harder it is to figure out what the test is actually testing.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @Trott.

Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW fccc0bf landed now you have common.mustCallAtLeast

});

// it would be nice if this worked:
res.on('data', common.mustCall());
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment here.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe replace with the longer but more explicit:

    let data = '';
    res.on('data', (chunk) => { data += chunk; });
    res.on('end', common.mustCall(() => {
      assert.strictEqual(data, 'Part of my res.');
    }));

This way it verifies all of these:

  • the data callback is called at least once
  • the data callback is sent the expected value(s)
  • the 'end callback is only fired after the data callback(s)

@@ -107,7 +107,8 @@ function check(tests) {
const test = tests[0];
let server;
if (test) {
server = http.createServer(serverHandler).listen(0, '127.0.0.1', client);
server = http.createServer(serverHandler)
.listen(0, '127.0.0.1', common.mustCall(client));
Copy link
Contributor

Choose a reason for hiding this comment

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

/s/127.0.0.1/common.localhostIPv4/

c.write(request_generator());
});
c.on('connect', common.mustCall(() => c.write(request_generator())));
c.on('data', common.mustCall((chunk) => server_response += chunk));
Copy link
Contributor

Choose a reason for hiding this comment

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

common.mustCall() takes an expected:int as second argument.
I'll write a PR to have it expect '+' as "more than zero".

@refack refack mentioned this pull request May 9, 2017
4 tasks
@mscdex mscdex added the http Issues or PRs related to the http subsystem. label May 9, 2017
@jasnell
Copy link
Member Author

jasnell commented Jul 24, 2017

Closing in favor of #14315

@jasnell jasnell closed this Jul 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http Issues or PRs related to the http subsystem. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants