Skip to content

Commit 9949d55

Browse files
Gabriel SchulhofMylesBorins
Gabriel Schulhof
authored andcommitted
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 <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
1 parent f29d8e0 commit 9949d55

File tree

2 files changed

+44
-38
lines changed

2 files changed

+44
-38
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict';
2+
3+
const common = require('../../common');
4+
const assert = require('assert');
5+
const async_hooks = require('async_hooks');
6+
const binding = require(`./build/${common.buildType}/binding`);
7+
const makeCallback = binding.makeCallback;
8+
9+
// Check async hooks integration using async context.
10+
const hook_result = {
11+
id: null,
12+
init_called: false,
13+
before_called: false,
14+
after_called: false,
15+
destroy_called: false,
16+
};
17+
const test_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

-38
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const common = require('../../common');
44
const assert = require('assert');
5-
const async_hooks = require('async_hooks');
65
const vm = require('vm');
76
const binding = require(`./build/${common.buildType}/binding`);
87
const makeCallback = 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-
const hook_result = {
87-
id: null,
88-
init_called: false,
89-
before_called: false,
90-
after_called: false,
91-
destroy_called: false,
92-
};
93-
const test_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)