-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
n-api: separate out async_hooks test
Place the test_make_callback async_hooks-related test into its own file. Backport-PR-URL: #19265 PR-URL: #19392 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
- Loading branch information
1 parent
f29d8e0
commit 9949d55
Showing
2 changed files
with
44 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict'; | ||
|
||
const common = require('../../common'); | ||
const assert = require('assert'); | ||
const async_hooks = require('async_hooks'); | ||
const binding = require(`./build/${common.buildType}/binding`); | ||
const makeCallback = binding.makeCallback; | ||
|
||
// Check async hooks integration using async context. | ||
const hook_result = { | ||
id: null, | ||
init_called: false, | ||
before_called: false, | ||
after_called: false, | ||
destroy_called: false, | ||
}; | ||
const test_hook = async_hooks.createHook({ | ||
init: (id, type) => { | ||
if (type === 'test') { | ||
hook_result.id = id; | ||
hook_result.init_called = true; | ||
} | ||
}, | ||
before: (id) => { | ||
if (id === hook_result.id) hook_result.before_called = true; | ||
}, | ||
after: (id) => { | ||
if (id === hook_result.id) hook_result.after_called = true; | ||
}, | ||
destroy: (id) => { | ||
if (id === hook_result.id) hook_result.destroy_called = true; | ||
}, | ||
}); | ||
|
||
test_hook.enable(); | ||
makeCallback(process, function() {}); | ||
|
||
assert.strictEqual(hook_result.init_called, true); | ||
assert.strictEqual(hook_result.before_called, true); | ||
assert.strictEqual(hook_result.after_called, true); | ||
setImmediate(() => { | ||
assert.strictEqual(hook_result.destroy_called, true); | ||
test_hook.disable(); | ||
}); |
This file contains 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