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: refactor the code in test-http-connect #10397

Closed
wants to merge 1 commit into from

Conversation

edsadr
Copy link
Member

@edsadr edsadr commented Dec 21, 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 common.mustCall to control the functions execution automatically
  • use let and const instead of var
  • use assert.strictEqual instead of assert.equal
  • use assert.strictEqual instead of assert.ok
  • use arrow functions

@nodejs-github-bot nodejs-github-bot added test Issues and PRs related to the tests. lts-watch-v6.x labels Dec 21, 2016
var data = firstBodyChunk.toString();
socket.on('data', function(buf) {
let data = firstBodyChunk.toString();
socket.on('data', common.mustCall((buf) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would avoid adding common.mustCall() to the data handler. The number of events emitted can potentially be different, and it isn't really needed for the test.

var data = firstBodyChunk.toString();
socket.on('data', function(buf) {
let data = firstBodyChunk.toString();
socket.on('data', common.mustCall((buf) => {
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.

assert.ok(serverGotConnect);
assert.ok(clientGotConnect);
process.on('exit', () => {
assert.strictEqual(serverGotConnect, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

By using common.mustCall(), I think these variables can be eliminated completely, as can this exit event handler.

@mscdex mscdex added the http Issues or PRs related to the http subsystem. label Dec 21, 2016
@edsadr
Copy link
Member Author

edsadr commented Dec 22, 2016

@cjihrig , just implemented your suggestions

@italoacasas
Copy link
Contributor

var clientRequestClosed = false;
req.on('close', function() {
let clientRequestClosed = false;
req.on('close', common.mustCall(() => {
clientRequestClosed = true;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: can't this be removed now? I mean the clientRequestClosed flag.

@edsadr
Copy link
Member Author

edsadr commented Dec 26, 2016

@lpinca removed as suggested, please set the CI again

@lpinca
Copy link
Member

lpinca commented Dec 26, 2016

assert.equal(req.url, 'google.com:443');
server.on('connect', common.mustCall((req, socket, firstBodyChunk) => {
assert.strictEqual(req.method, 'CONNECT');
assert.strictEqual(req.url, 'google.com:443');
console.error('Server got CONNECT request');
Copy link
Member

Choose a reason for hiding this comment

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

Nit: this can also probably be removed.


req.on('connect', function(res, socket, firstBodyChunk) {
req.on('connect', common.mustCall((res, socket, firstBodyChunk) => {
console.error('Client got CONNECT request');
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

* use common.mustCall to control the functions execution automatically
* use let and const instead of var
* use assert.strictEqual instead of assert.equal
* use arrow functions
* remove console.error and unnecessary variables
@edsadr
Copy link
Member Author

edsadr commented Dec 26, 2016

@lpinca removed those too

@lpinca
Copy link
Member

lpinca commented Dec 30, 2016

New CI before landing: https://ci.nodejs.org/job/node-test-pull-request/5635/

@lpinca
Copy link
Member

lpinca commented Dec 30, 2016

Landed in 72a8488.

@lpinca lpinca closed this Dec 30, 2016
lpinca pushed a commit that referenced this pull request Dec 30, 2016
* use common.mustCall to control the functions execution automatically
* use let and const instead of var
* use assert.strictEqual instead of assert.equal
* use arrow functions
* remove console.error and unnecessary variables

PR-URL: #10397
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
evanlucas pushed a commit that referenced this pull request Jan 3, 2017
* use common.mustCall to control the functions execution automatically
* use let and const instead of var
* use assert.strictEqual instead of assert.equal
* use arrow functions
* remove console.error and unnecessary variables

PR-URL: #10397
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
evanlucas pushed a commit that referenced this pull request Jan 4, 2017
* use common.mustCall to control the functions execution automatically
* use let and const instead of var
* use assert.strictEqual instead of assert.equal
* use arrow functions
* remove console.error and unnecessary variables

PR-URL: #10397
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
MylesBorins pushed a commit that referenced this pull request Jan 23, 2017
* use common.mustCall to control the functions execution automatically
* use let and const instead of var
* use assert.strictEqual instead of assert.equal
* use arrow functions
* remove console.error and unnecessary variables

PR-URL: #10397
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
MylesBorins pushed a commit that referenced this pull request Jan 24, 2017
* use common.mustCall to control the functions execution automatically
* use let and const instead of var
* use assert.strictEqual instead of assert.equal
* use arrow functions
* remove console.error and unnecessary variables

PR-URL: #10397
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Jan 24, 2017
MylesBorins pushed a commit that referenced this pull request Jan 31, 2017
* use common.mustCall to control the functions execution automatically
* use let and const instead of var
* use assert.strictEqual instead of assert.equal
* use arrow functions
* remove console.error and unnecessary variables

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

Successfully merging this pull request may close these issues.

8 participants