1
1
'use strict' ;
2
- const buildType = process . config . target_defaults . default_configuration ;
2
+
3
3
const assert = require ( 'assert' ) ;
4
4
const common = require ( './common' ) ;
5
5
@@ -17,14 +17,27 @@ function checkAsyncHooks() {
17
17
return false ;
18
18
}
19
19
20
- test ( require ( `./build/${ buildType } /binding.node` ) ) ;
21
- test ( require ( `./build/${ buildType } /binding_noexcept.node` ) ) ;
20
+ module . exports = common . runTest ( test ) ;
22
21
23
22
function installAsyncHooksForTest ( ) {
24
23
return new Promise ( ( resolve , reject ) => {
25
24
let id ;
26
25
const events = [ ] ;
27
- const hook = async_hooks . createHook ( {
26
+ /**
27
+ * TODO(legendecas): investigate why resolving & disabling hooks in
28
+ * destroy callback causing crash with case 'callbackscope.js'.
29
+ */
30
+ let hook ;
31
+ let destroyed = false ;
32
+ const interval = setInterval ( ( ) => {
33
+ if ( destroyed ) {
34
+ hook . disable ( ) ;
35
+ clearInterval ( interval ) ;
36
+ resolve ( events ) ;
37
+ }
38
+ } , 10 ) ;
39
+
40
+ hook = async_hooks . createHook ( {
28
41
init ( asyncId , type , triggerAsyncId , resource ) {
29
42
if ( id === undefined && type === 'async_context_test' ) {
30
43
id = asyncId ;
@@ -44,30 +57,30 @@ function installAsyncHooksForTest() {
44
57
destroy ( asyncId ) {
45
58
if ( asyncId === id ) {
46
59
events . push ( { eventName : 'destroy' } ) ;
47
- hook . disable ( ) ;
48
- resolve ( events ) ;
60
+ destroyed = true ;
49
61
}
50
62
}
51
63
} ) . enable ( ) ;
52
64
} ) ;
53
65
}
54
66
55
67
function test ( binding ) {
56
- binding . asynccontext . makeCallback ( common . mustCall ( ) , { foo : 'foo' } ) ;
57
- if ( ! checkAsyncHooks ( ) )
68
+ if ( ! checkAsyncHooks ( ) ) {
58
69
return ;
70
+ }
59
71
60
72
const hooks = installAsyncHooksForTest ( ) ;
61
73
const triggerAsyncId = async_hooks . executionAsyncId ( ) ;
62
- hooks . then ( actual => {
63
- assert . deepStrictEqual ( actual , [
64
- { eventName : 'init' ,
65
- type : 'async_context_test' ,
66
- triggerAsyncId : triggerAsyncId ,
67
- resource : { foo : 'foo' } } ,
68
- { eventName : 'before' } ,
69
- { eventName : 'after' } ,
70
- { eventName : 'destroy' }
71
- ] ) ;
74
+ binding . asynccontext . makeCallback ( common . mustCall ( ) , { foo : 'foo' } ) ;
75
+ return hooks . then ( actual => {
76
+ assert . deepStrictEqual ( actual , [
77
+ { eventName : 'init' ,
78
+ type : 'async_context_test' ,
79
+ triggerAsyncId : triggerAsyncId ,
80
+ resource : { foo : 'foo' } } ,
81
+ { eventName : 'before' } ,
82
+ { eventName : 'after' } ,
83
+ { eventName : 'destroy' }
84
+ ] ) ;
72
85
} ) . catch ( common . mustNotCall ( ) ) ;
73
86
}
0 commit comments