forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-async-hook-inspector.js
More file actions
55 lines (44 loc) · 1.96 KB
/
test-async-hook-inspector.js
File metadata and controls
55 lines (44 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
common.skipIf32Bits();
const assert = require('assert');
const async_hooks = require('async_hooks');
const inspector = require('inspector');
// Verify that inspector-async-hook is not registered,
// thus emitInit() ignores invalid arguments
// See test/async-hooks/test-emit-init.js
function verifyAsyncHookDisabled(message) {
assert.doesNotThrow(() => async_hooks.emitInit(), message);
}
// Verify that inspector-async-hook is registered
// by checking that emitInit with invalid arguments
// throw an error.
// See test/async-hooks/test-emit-init.js
function verifyAsyncHookEnabled(message) {
assert.throws(() => async_hooks.emitInit(), message);
}
// By default inspector async hooks should not have been installed.
verifyAsyncHookDisabled('inspector async hook should be disabled at startup');
const session = new inspector.Session();
verifyAsyncHookDisabled('creating a session should not enable async hooks');
session.connect();
verifyAsyncHookDisabled('creating a session should not enable async hooks');
session.post('Debugger.setAsyncCallStackDepth', { invalid: 'message' }, () => {
verifyAsyncHookDisabled('invalid message should not enable async hooks');
session.post('Debugger.setAsyncCallStackDepth', { maxDepth: 'five' }, () => {
verifyAsyncHookDisabled('invalid maxDepth (sting) should not enable async' +
' hooks');
session.post('Debugger.setAsyncCallStackDepth', { maxDepth: NaN }, () => {
verifyAsyncHookDisabled('invalid maxDepth (NaN) should not enable async' +
' hooks');
session.post('Debugger.setAsyncCallStackDepth', { maxDepth: 10 }, () => {
verifyAsyncHookEnabled('valid message should enable async hook');
session.post('Debugger.setAsyncCallStackDepth', { maxDepth: 0 }, () => {
verifyAsyncHookDisabled('Setting maxDepth to 0 should disable ' +
'async hooks');
});
});
});
});
});