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: add coverage for AsyncResource constructor #13327

Closed
wants to merge 1 commit into from
Closed

test: add coverage for AsyncResource constructor #13327

wants to merge 1 commit into from

Conversation

gergelyke
Copy link
Contributor

@gergelyke gergelyke commented May 31, 2017

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)

async_hooks

@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label May 31, 2017
@mscdex mscdex added the async_hooks Issues and PRs related to the async hooks subsystem. label May 31, 2017

assert.throws(() => {
return new AsyncResource()
}, new RegExp('^TypeError: type must be a string with length > 0'));
Copy link
Member

Choose a reason for hiding this comment

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

Why not lexical regexes? e.g.

/^TypeError: type must be a string with length > 0$/

@gergelyke
Copy link
Contributor Author

@jasnell updated

const AsyncResource = require('async_hooks').AsyncResource;
const async_wrap = process.binding('async_wrap');

async_wrap.async_hook_fields[async_wrap.constants.kInit] = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Mind adding a comment as to why this line is needed?

@gergelyke
Copy link
Contributor Author

@trevnorris updated

async_wrap.async_hook_fields[async_wrap.constants.kInit] = 1;

assert.throws(() => {
return new AsyncResource()
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this pass make lint without the semicolon?

const AsyncResource = require('async_hooks').AsyncResource;
const async_wrap = process.binding('async_wrap');

// without this, there is nothing to do, and the constructor would return immediatly
Copy link
Contributor

Choose a reason for hiding this comment

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

immediately

@gergelyke
Copy link
Contributor Author

@Fishrock123 thanks, updated!

Copy link
Contributor

@trevnorris trevnorris left a comment

Choose a reason for hiding this comment

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

Almost all good, but might want to wait for one change to AsyncResource before landing this.

/* without this, there is nothing to do,
* and the constructor would return immediately
*/
async_wrap.async_hook_fields[async_wrap.constants.kInit] = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Refering to #13336 (comment) the logic there in AsyncResource() is bad, so this shouldn't be necessary. If this lands first we need a comment or such that this should be removed.

Also, I'd rather see

async_hooks.createHook({ init() { } }).enable();

than manipulating kInit manually.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense - should I change it to async_hooks.createHook, or remove it entirely and wait for it to be fixed?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd change it and wait for the fix. If there's already a PR w/ the fix then we'll get it in quick. If not then I'll make one. Either way it's a simple fix that shouldn't take more than a day to get landed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated - also, I am happy to submit a PR for the fix as well. let me know if you'd like that


assert.throws(() => {
return new AsyncResource();
}, new RegExp('^TypeError: type must be a string with length > 0$'));
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure @jasnell’s nit was actually addressed… why are these new RegExp() calls? It might be confusing to readers of our tests because we almost exclusively use them to create dynamic regexes that depend on variables.

Copy link
Member

Choose a reason for hiding this comment

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

No, my comments were not addressed. I would prefer to see the /..../ regex pattern used but I'm fine with this either way.

Copy link
Contributor

@refack refack left a comment

Choose a reason for hiding this comment

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

LTGM % RegEx to literals

@addaleax
Copy link
Member

addaleax commented Jun 9, 2017

Landed in 52f358b, fixed up nits & linter while landing. Thanks for the PR!

@addaleax addaleax closed this Jun 9, 2017
addaleax pushed a commit that referenced this pull request Jun 9, 2017
PR-URL: #13327
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
addaleax pushed a commit that referenced this pull request Jun 10, 2017
PR-URL: #13327
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
@addaleax addaleax mentioned this pull request Jun 10, 2017
@gibfahn gibfahn mentioned this pull request Jun 15, 2017
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
async_hooks Issues and PRs related to the async hooks subsystem. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants