-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
Conversation
|
||
assert.throws(() => { | ||
return new AsyncResource() | ||
}, new RegExp('^TypeError: type must be a string with length > 0')); |
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.
Why not lexical regexes? e.g.
/^TypeError: type must be a string with length > 0$/
@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; |
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.
Mind adding a comment as to why this line is needed?
@trevnorris updated |
async_wrap.async_hook_fields[async_wrap.constants.kInit] = 1; | ||
|
||
assert.throws(() => { | ||
return new AsyncResource() |
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.
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 |
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.
immediately
@Fishrock123 thanks, updated! |
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.
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; |
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.
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.
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.
makes sense - should I change it to async_hooks.createHook
, or remove it entirely and wait for it to be fixed?
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'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.
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.
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$')); |
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 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.
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.
No, my comments were not addressed. I would prefer to see the /..../
regex pattern used but I'm fine with this either way.
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.
LTGM % RegEx
to literals
Landed in 52f358b, fixed up nits & linter while landing. Thanks for the PR! |
PR-URL: #13327 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
PR-URL: #13327 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
async_hooks