FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Converting test to use Countdown by TomerOmri · Pull Request #17505 · nodejs/node · GitHub

/ node Public

Converting test to use Countdown - #17505

Closed
TomerOmri wants to merge 9 commits into
nodejs:masterfrom
TomerOmri:countdown
Closed

Converting test to use Countdown#17505
TomerOmri wants to merge 9 commits into
nodejs:masterfrom
TomerOmri:countdown

Conversation

TomerOmri commented Dec 6, 2017
edited by apapirovski
Loading

Copy link
Copy Markdown

Hi,
this is my first PR :)
I worked on test-http-should-keep-alive.js
Ref: #17169

#Goodness squad

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

nodejs-github-bot added the test Issues and PRs related to the tests. label Dec 6, 2017

apapirovski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks for the contribution @TomerOmri. Since this is using Countdown now, it should be possible to refactor such that the requests and responses counters are no longer necessary.

Since there's always only one makeRequest in progress, we could for example use something like this in makeRequest:

response = SERVER_RESPONSES.shift();
shouldKeepAlive = SHOULD_KEEP_ALIVE.shift();

where response and shouldKeepAlive are declared in the top scope (and can then be used within both the client handler and the server one).

process.on('exit', function() {
assert.strictEqual(2, testsComplete);
});
}); No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This appears to be an unrelated change. The newline should remain.

assert.strictEqual(actualRequests, expectRequests);
console.log('ok');
});
}); No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Same here. Unrelated change, newline should remain.

makeRequest();
});


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Unrelated change, please remove.


process.on('exit', function() {
assert.strictEqual(requests, SERVER_RESPONSES.length);
assert.strictEqual(responses, SHOULD_KEEP_ALIVE.length);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This whole process.on('exit') block shouldn't be necessary if we're trying to use Countdown.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Hi, Thanks for the quick response,
I will be happy if you can clarify some things:

  1. i kept the "requests" and the "responses" variables because they are used on SERVER_RESPONSES[requests] under the makeRequest function.
    since those variables are used inside of an Array if we use countdown we will get another value from the array SERVER_RESPONSES.
    can you be more clear about your solution with the shift() ?

  2. should I make another countdown instance for requests as well?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

There are two directions this can go in.

  1. Instead of using requests and responses, just use SERVER_RESPONSES.length - countdown.remaining — that will get you the same index.
  2. shift removes and returns the element within an array that's at index 0. You can use this to store the current value from SERVER_RESPONSES and SHOULD_KEEP_ALIVE.

Copy link
Copy Markdown
Author

Hi @apapirovski after an update,
waiting for your review.
Thanks!

const assert = require('assert');
const http = require('http');
const net = require('net');
const common = require('../common');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This needs to be the first include within the file. Could you update?

http.globalAgent.maxSockets = 5;

const countdown = new Countdown(SHOULD_KEEP_ALIVE.length , () => server.close());
let countdownIndexInc = SERVER_RESPONSES.length - countdown.remaining;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

You won't be able to store this in a variable since it won't update. I suppose you could make it a function if you want to avoid having to repeat it everywhere... const getCountdownIndex = () => SERVER_RESPONSES.length - countdown.remaining and then call it as getCountdownIndex().

assert.strictEqual(responses, SHOULD_KEEP_ALIVE.length);
countdownIndexInc = SERVER_RESPONSES.length - countdown.remaining;
assert.strictEqual(countdownIndexInc, SERVER_RESPONSES.length);
assert.strictEqual(countdownIndexInc, SHOULD_KEEP_ALIVE.length);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This block can be removed altogether. The process won't exit unless the countdown finishes.

apapirovski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

A few small things left.

const countdown = new Countdown(SHOULD_KEEP_ALIVE.length , () => server.close());
let countdownIndexInc = SERVER_RESPONSES.length - countdown.remaining;

const getCountdownIndex = () => SERVER_RESPONSES.length - countdown.remaining

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Nit: missing semi-colon.


'use strict';
require('../common');
const common = require('../common');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Just noticed but I don't think this const common is actually used? In general, I recommend running make test -j4 — it will run eslint to make sure there are no small issues like this.

// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
require('../common');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'm sorry, I should've been clearer. This is still required but it should not be assigned to a variable. Also, please try to run make test -j4 before committing as it will flag these types of issues in advance and also run the test being modified.

Copy link
Copy Markdown
Author

Hi @apapirovski
Thanks for the help im still learning. the make test -j4` runs with no issues.

Let me know if you find anything else that need to be changed.
Thanks!


'use strict';
require('../common');
-require('../common');

apapirovski Dec 7, 2017
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Almost all good but it looks like there's a - sign ahead of the require statement. Could you remove? Thanks!


const countdown = new Countdown(SHOULD_KEEP_ALIVE.length , () => server.close());

const getCountdownIndex = () => SERVER_RESPONSES.length - countdown.remaining

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It seems like there's still no semi-colon at the end of this line btw.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Hi, I`m probably not running the eslint as should. the command
just pass without no issues.
how can I make sure its ok?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

You could try running make lint-js from your command line, that should lint the files. The -require might not be caught but the missing semi-colon definitely should.

maclover7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

One quick comment

let responses = 0;
http.globalAgent.maxSockets = 5;

const countdown = new Countdown(SHOULD_KEEP_ALIVE.length , () => server.close());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Can you please remove the space between length and the comma?

Copy link
Copy Markdown
Contributor

maclover7 added the author ready PRs that have at least one approval, no outstanding review comments, and a CI started. label Dec 9, 2017

Copy link
Copy Markdown
Contributor

Landing...

maclover7 self-assigned this Dec 9, 2017

Copy link
Copy Markdown
Contributor

Landed in e9d1e12, congrats on your first PR to Node.js!
❤️ 💚 💙 💛 💜

maclover7 closed this Dec 9, 2017
MylesBorins pushed a commit that referenced this pull request Dec 12, 2017
PR-URL: #17505
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
MylesBorins pushed a commit that referenced this pull request Dec 12, 2017
PR-URL: #17505
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
MylesBorins mentioned this pull request Dec 12, 2017
addaleax removed the author ready PRs that have at least one approval, no outstanding review comments, and a CI started. label Dec 13, 2017
gibfahn pushed a commit that referenced this pull request Dec 20, 2017
PR-URL: #17505
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
gibfahn pushed a commit that referenced this pull request Dec 20, 2017
PR-URL: #17505
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
gibfahn mentioned this pull request Dec 20, 2017
gibfahn pushed a commit that referenced this pull request Dec 20, 2017
PR-URL: #17505
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
gibfahn mentioned this pull request Dec 20, 2017
MylesBorins mentioned this pull request Dec 20, 2017
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test Issues and PRs related to the tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants


Back | FazBrowse Home | New Git URL