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 the code in test-pipe.js #10452

Closed
wants to merge 1 commit into from
Closed

Conversation

edsadr
Copy link
Member

@edsadr edsadr commented Dec 25, 2016

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)

test

Description of change
  • use const and let instead of var
  • use common.mustCall to control functions executions
  • use assert.strictEqual instead of assert.equal
  • use assert.ifError to handle errors
  • use arrow functions

@nodejs-github-bot nodejs-github-bot added test Issues and PRs related to the tests. lts-watch-v6.x labels Dec 25, 2016

req.pipe(socket);

req.on('end', function() {
req.on('end', common.mustCall(() => {
res.writeHead(200);
res.write('thanks');
res.end();
console.log('response with \'thanks\'');
Copy link
Contributor

@mscdex mscdex Dec 25, 2016

Choose a reason for hiding this comment

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

Can we remove these log statements too? Also the process.stdout.write() statements.


req.connection.on('error', function(e) {
req.connection.on('error', (e) => {
assert.ifError(e);
console.log('http server-side error: ' + e.message);
process.exit(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can be removed now that we're asserting.

@mscdex mscdex added http Issues or PRs related to the http subsystem. net Issues and PRs related to the net subsystem. labels Dec 25, 2016
@edsadr
Copy link
Member Author

edsadr commented Dec 25, 2016

@mscdex, changed as suggested

@mscdex
Copy link
Contributor

mscdex commented Dec 25, 2016

@mscdex
Copy link
Contributor

mscdex commented Dec 26, 2016

LGTM

res.setEncoding('utf8');
res.on('data', function(string) {
assert.equal('thanks', string);
res.on('data', (string) => {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: how about wrapping this listener with common.mustCall and remove the gotThanks flag?

Copy link
Member Author

@edsadr edsadr Dec 27, 2016

Choose a reason for hiding this comment

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

@lpinca the problem adding the common.mustCall for this event, is that we are not sure about the exact number of times this function will be called, every time the test run the number could be different, so adding it will make the test to fail sporadically

Copy link
Member

Choose a reason for hiding this comment

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

@edsadr there is an assertion which basically check that the listener is called once.

assert.strictEqual('thanks', string);

If the are multiple chunks then the assertion fails anyway.

* use const and let instead of var
* use common.mustCall to control functions executions
* use assert.strictEqual instead of assert.equal
* use assert.ifError to handle errors
* use arrow functions
* remove console.log and process.stdout.write
@edsadr
Copy link
Member Author

edsadr commented Dec 27, 2016

@lpinca , I stand corrected I was checking the other event:

s.on('data', (d) => {
    tcpLengthSeen += d.length;
    for (let j = 0; j < d.length; j++) {
      assert.strictEqual(buffer[i], d[j]);
      i++;
    }
  });

That one is the one being called multiple times, just fixed the one you suggested and I guess just left to set the CI

@lpinca
Copy link
Member

lpinca commented Dec 27, 2016

@italoacasas
Copy link
Contributor

Landed fc103bb

evanlucas pushed a commit that referenced this pull request Jan 3, 2017
* use const and let instead of var
* use common.mustCall to control functions executions
* use assert.strictEqual instead of assert.equal
* use assert.ifError to handle errors
* use arrow functions
* remove console.log and process.stdout.write

PR-URL: #10452
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Brian White <[email protected]>
evanlucas pushed a commit that referenced this pull request Jan 4, 2017
* use const and let instead of var
* use common.mustCall to control functions executions
* use assert.strictEqual instead of assert.equal
* use assert.ifError to handle errors
* use arrow functions
* remove console.log and process.stdout.write

PR-URL: #10452
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Brian White <[email protected]>
MylesBorins pushed a commit that referenced this pull request Jan 23, 2017
* use const and let instead of var
* use common.mustCall to control functions executions
* use assert.strictEqual instead of assert.equal
* use assert.ifError to handle errors
* use arrow functions
* remove console.log and process.stdout.write

PR-URL: #10452
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Brian White <[email protected]>
MylesBorins pushed a commit that referenced this pull request Jan 23, 2017
* use const and let instead of var
* use common.mustCall to control functions executions
* use assert.strictEqual instead of assert.equal
* use assert.ifError to handle errors
* use arrow functions
* remove console.log and process.stdout.write

PR-URL: #10452
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Brian White <[email protected]>
MylesBorins pushed a commit that referenced this pull request Jan 24, 2017
* use const and let instead of var
* use common.mustCall to control functions executions
* use assert.strictEqual instead of assert.equal
* use assert.ifError to handle errors
* use arrow functions
* remove console.log and process.stdout.write

PR-URL: #10452
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Brian White <[email protected]>
MylesBorins pushed a commit that referenced this pull request Jan 24, 2017
* use const and let instead of var
* use common.mustCall to control functions executions
* use assert.strictEqual instead of assert.equal
* use assert.ifError to handle errors
* use arrow functions
* remove console.log and process.stdout.write

PR-URL: #10452
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Brian White <[email protected]>
This was referenced Jan 24, 2017
MylesBorins pushed a commit that referenced this pull request Jan 31, 2017
* use const and let instead of var
* use common.mustCall to control functions executions
* use assert.strictEqual instead of assert.equal
* use assert.ifError to handle errors
* use arrow functions
* remove console.log and process.stdout.write

PR-URL: #10452
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Brian White <[email protected]>
MylesBorins pushed a commit that referenced this pull request Feb 1, 2017
* use const and let instead of var
* use common.mustCall to control functions executions
* use assert.strictEqual instead of assert.equal
* use assert.ifError to handle errors
* use arrow functions
* remove console.log and process.stdout.write

PR-URL: #10452
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Brian White <[email protected]>
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. net Issues and PRs related to the net subsystem. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants