Skip to content

Commit 87f7453

Browse files
Gabriel SchulhofMylesBorins
authored andcommitted
n-api: separate out async_hooks test
Place the test_make_callback async_hooks-related test into its own file. PR-URL: #19392 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent b43b05d commit 87f7453

File tree

2 files changed

+44
-38
lines changed

2 files changed

+44
-38
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict';
2+
3+
constcommon=require('../../common');
4+
constassert=require('assert');
5+
constasync_hooks=require('async_hooks');
6+
constbinding=require(`./build/${common.buildType}/binding`);
7+
constmakeCallback=binding.makeCallback;
8+
9+
// Check async hooks integration using async context.
10+
consthook_result={
11+
id: null,
12+
init_called: false,
13+
before_called: false,
14+
after_called: false,
15+
destroy_called: false,
16+
};
17+
consttest_hook=async_hooks.createHook({
18+
init: (id,type)=>{
19+
if(type==='test'){
20+
hook_result.id=id;
21+
hook_result.init_called=true;
22+
}
23+
},
24+
before: (id)=>{
25+
if(id===hook_result.id)hook_result.before_called=true;
26+
},
27+
after: (id)=>{
28+
if(id===hook_result.id)hook_result.after_called=true;
29+
},
30+
destroy: (id)=>{
31+
if(id===hook_result.id)hook_result.destroy_called=true;
32+
},
33+
});
34+
35+
test_hook.enable();
36+
makeCallback(process,function(){});
37+
38+
assert.strictEqual(hook_result.init_called,true);
39+
assert.strictEqual(hook_result.before_called,true);
40+
assert.strictEqual(hook_result.after_called,true);
41+
setImmediate(()=>{
42+
assert.strictEqual(hook_result.destroy_called,true);
43+
test_hook.disable();
44+
});

‎test/addons-napi/test_make_callback/test.js‎

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
constcommon=require('../../common');
44
constassert=require('assert');
5-
constasync_hooks=require('async_hooks');
65
constvm=require('vm');
76
constbinding=require(`./build/${common.buildType}/binding`);
87
constmakeCallback=binding.makeCallback;
@@ -81,40 +80,3 @@ function endpoint($Object){
8180
}
8281

8382
assert.strictEqual(Object,makeCallback(process,forward,endpoint));
84-
85-
// Check async hooks integration using async context.
86-
consthook_result={
87-
id: null,
88-
init_called: false,
89-
before_called: false,
90-
after_called: false,
91-
destroy_called: false,
92-
};
93-
consttest_hook=async_hooks.createHook({
94-
init: (id,type)=>{
95-
if(type==='test'){
96-
hook_result.id=id;
97-
hook_result.init_called=true;
98-
}
99-
},
100-
before: (id)=>{
101-
if(id===hook_result.id)hook_result.before_called=true;
102-
},
103-
after: (id)=>{
104-
if(id===hook_result.id)hook_result.after_called=true;
105-
},
106-
destroy: (id)=>{
107-
if(id===hook_result.id)hook_result.destroy_called=true;
108-
},
109-
});
110-
111-
test_hook.enable();
112-
makeCallback(process,function(){});
113-
114-
assert.strictEqual(hook_result.init_called,true);
115-
assert.strictEqual(hook_result.before_called,true);
116-
assert.strictEqual(hook_result.after_called,true);
117-
setImmediate(()=>{
118-
assert.strictEqual(hook_result.destroy_called,true);
119-
test_hook.disable();
120-
});

0 commit comments

Comments
(0)