forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-emit-init.js
More file actions
49 lines (39 loc) · 1.66 KB
/
test-emit-init.js
File metadata and controls
49 lines (39 loc) · 1.66 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
'use strict';
const common = require('../common');
const assert = require('assert');
const async_hooks = require('async_hooks');
const initHooks = require('./init-hooks');
// Verify that if there is no registered hook, then those invalid parameters
// won't be checked.
assert.doesNotThrow(() => async_hooks.emitInit());
const expectedId = async_hooks.newUid();
const expectedTriggerId = async_hooks.newUid();
const expectedType = 'test_emit_init_type';
const expectedResource = { key: 'test_emit_init_resource' };
const hooks1 = initHooks({
oninit: common.mustCall((id, type, triggerId, resource) => {
assert.strictEqual(id, expectedId);
assert.strictEqual(type, expectedType);
assert.strictEqual(triggerId, expectedTriggerId);
assert.strictEqual(resource.key, expectedResource.key);
})
});
hooks1.enable();
assert.throws(() => async_hooks.emitInit(),
/^RangeError: asyncId must be an unsigned integer$/);
assert.throws(() => async_hooks.emitInit(expectedId),
/^TypeError: type must be a string with length > 0$/);
assert.throws(() => async_hooks.emitInit(expectedId, expectedType, -1),
/^RangeError: triggerId must be an unsigned integer$/);
async_hooks.emitInit(expectedId, expectedType, expectedTriggerId,
expectedResource);
hooks1.disable();
initHooks({
oninit: common.mustCall((id, type, triggerId, resource) => {
assert.strictEqual(id, expectedId);
assert.strictEqual(type, expectedType);
assert.notStrictEqual(triggerId, expectedTriggerId);
assert.strictEqual(resource.key, expectedResource.key);
})
}).enable();
async_hooks.emitInit(expectedId, expectedType, expectedResource);