Uh oh!
There was an error while loading. Please reload this page.
test: increase coverage of async_hooks - #13336
Conversation
kunalspathak
commented
May 31, 2017
Unrelated to this PR, but I noticed that we |
There was a problem hiding this comment.
I think this test can go into parallel (it doesn’t use any of the async hook test helpers here)
385a979 to
629f23bCompareAndreasMadsen
commented
Jun 1, 2017
Sigh, I guess it is because it doesn't appear in https://github.com/nodejs/node/blob/master/vcbuild.bat#L68L82 |
629f23b to
d44fb25Comparekunalspathak
commented
Jun 1, 2017
Yep, that was my question 😄 . Why is it not present in |
AndreasMadsen
commented
Jun 1, 2017
/cc @refack regarding |
refack
commented
Jun 1, 2017
AFAIK there's no reason except nobody bothered to add it. |
refack
commented
Jun 1, 2017
Cross-ref: #13378 |
DavidCai1111
commented
Jun 2, 2017
AndreasMadsen
left a comment
There was a problem hiding this comment.
LGTM, I don't think we need to wait for the windows PR to be merged. These are mostly pure JS logic related tests.
trevnorris
left a comment
There was a problem hiding this comment.
Thanks for doing all this. Test coverage for async_hooks is important and happy to see more of it coming in. I have two suggestions and one of your test additions made me aware of a flaw in the AsyncResource() constructor logic that needs to be fixed.
There was a problem hiding this comment.
There's the problem where if test_init_callback is never hit then the common.mustCall() will never run. Instead you'll need to do it like this:
constoninitMustCall=common.mustCall(()=>{thrownewError('test_init_callback');});switch(process.argv[2]){case'test_init_callback':
initHooks({oninit: oninitMustCall}).enable();There was a problem hiding this comment.
😕 But IMO the actual intention here is just to ensure that the common.mustCall() will run only when the test_init_callback case is hit? Every switch case will be hit in different process because of spawnSync()s below.
There was a problem hiding this comment.
But IMO the actual intention here is just to ensure that the
common.mustCall()will run only when the test_init_callback case is hit?
Whoops. Missed that. You're correct.
There was a problem hiding this comment.
I screwed up the logic here. It shouldn't return early before the arguments are checked. Otherwise it'll cause an async hook stack corruption. Here's the minimal test case:
new(require('async_hooks').AsyncResource)().emitBefore();Here's the diff for the fix. Feel free to add it to this PR along with the above test case:
diff --git a/lib/async_hooks.js b/lib/async_hooks.js
index d5d5407..aec73ed 100644
--- a/lib/async_hooks.js+++ b/lib/async_hooks.js@@ -205,15 +205,15 @@ class AsyncResource {
}
this[trigger_id_symbol] = triggerId;
- // Return immediately if there's nothing to do.- if (async_hook_fields[kInit] === 0)- return;-
if (typeof type !== 'string' || type.length <= 0)
throw new TypeError('type must be a string with length > 0');
if (!Number.isSafeInteger(triggerId) || triggerId < 0)
throw new RangeError('triggerId must be an unsigned integer');
+ // Return immediately if there's nothing to do.+ if (async_hook_fields[kInit] === 0)+ return;+
processing_hook = true;
for (var i = 0; i < active_hooks_array.length; i++) {
if (typeof active_hooks_array[i][init_symbol] === 'function') {There was a problem hiding this comment.
OK, i'll do it in this PR :=)
There was a problem hiding this comment.
@trevnorris Done, added the diff to this PR, PTAL :=)
There was a problem hiding this comment.
To make sure these run I' possibly do this:
constemitBeforeMustCall=common.mustCall(()=>async_hooks.emitBefore(-1));switch(process.argv[2]){case'test_invalid_async_id':
emitBeforeMustCall();refack
commented
Jun 4, 2017
Needs a rebase (just tried locally it goes smooth) |
d44fb25 to
69098bbCompareDavidCai1111
commented
Jun 5, 2017
@refack I rebased it locally and the result shows that it goes very smooth 😃 |
refack
commented
Jun 5, 2017
Apparently GitHub is a whiny little ... |
DavidCai1111
commented
Jun 6, 2017
@refack Now no conflicts checking and CI both seems good ... |
DavidCai1111
commented
Jun 6, 2017
@trevnorris PTAL |
trevnorris
commented
Jun 6, 2017
@DavidCai1993 Much thanks for the fix. |
DavidCai1111
commented
Jun 7, 2017
Landed in 35353a4 |
PR-URL: #13336 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
PR-URL: #13336 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
PR-URL: nodejs#13378 Refs: nodejs#13340 Refs: nodejs#13336 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: João Reis <reis@janeasystems.com>
lib/async_hooks.jstest/async_hooks/test-embedder.api.async-event.*.jstotest/async_hooks/test-embedder.api.async-resource.*.jsChecklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
async_hooks