-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
Conversation
|
||
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\''); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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, changed as suggested |
LGTM |
res.setEncoding('utf8'); | ||
res.on('data', function(string) { | ||
assert.equal('thanks', string); | ||
res.on('data', (string) => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
@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 |
Landed fc103bb |
* 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 <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
* 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 <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
* 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 <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
* 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 <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
* 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 <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
* 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 <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
* 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 <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
* 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 <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test
Description of change