@@ -34,13 +34,13 @@ class ActivityCollector {
34
34
this . _logid = logid ;
35
35
this . _logtype = logtype ;
36
36
37
- // register event handlers if provided
37
+ // Register event handlers if provided
38
38
this . oninit = typeof oninit === 'function' ? oninit : noop ;
39
39
this . onbefore = typeof onbefore === 'function' ? onbefore : noop ;
40
40
this . onafter = typeof onafter === 'function' ? onafter : noop ;
41
41
this . ondestroy = typeof ondestroy === 'function' ? ondestroy : noop ;
42
42
43
- // create the hook with which we'll collect activity data
43
+ // Create the hook with which we'll collect activity data
44
44
this . _asyncHook = async_hooks . createHook ( {
45
45
init : this . _init . bind ( this ) ,
46
46
before : this . _before . bind ( this ) ,
@@ -106,10 +106,15 @@ class ActivityCollector {
106
106
'\nExpected "destroy" to be called after "after"' ) ;
107
107
}
108
108
}
109
+ if ( ! a . handleIsObject ) {
110
+ v ( 'No resource object\n' + activityString ( a ) +
111
+ '\nExpected "init" to be called with a resource object' ) ;
112
+ }
109
113
}
110
114
if ( violations . length ) {
111
- console . error ( violations . join ( '\n' ) ) ;
112
- assert . fail ( violations . length , 0 , `Failed sanity checks: ${ violations } ` ) ;
115
+ console . error ( violations . join ( '\n\n' ) + '\n' ) ;
116
+ assert . fail ( violations . length , 0 ,
117
+ `${ violations . length } failed sanity checks` ) ;
113
118
}
114
119
}
115
120
@@ -143,11 +148,11 @@ class ActivityCollector {
143
148
_getActivity ( uid , hook ) {
144
149
const h = this . _activities . get ( uid ) ;
145
150
if ( ! h ) {
146
- // if we allowed handles without init we ignore any further life time
151
+ // If we allowed handles without init we ignore any further life time
147
152
// events this makes sense for a few tests in which we enable some hooks
148
153
// later
149
154
if ( this . _allowNoInit ) {
150
- const stub = { uid, type : 'Unknown' } ;
155
+ const stub = { uid, type : 'Unknown' , handleIsObject : true } ;
151
156
this . _activities . set ( uid , stub ) ;
152
157
return stub ;
153
158
} else {
@@ -163,7 +168,14 @@ class ActivityCollector {
163
168
}
164
169
165
170
_init ( uid , type , triggerAsyncId , handle ) {
166
- const activity = { uid, type, triggerAsyncId } ;
171
+ const activity = {
172
+ uid,
173
+ type,
174
+ triggerAsyncId,
175
+ // In some cases (e.g. Timeout) the handle is a function, thus the usual
176
+ // `typeof handle === 'object' && handle !== null` check can't be used.
177
+ handleIsObject : handle instanceof Object
178
+ } ;
167
179
this . _stamp ( activity , 'init' ) ;
168
180
this . _activities . set ( uid , activity ) ;
169
181
this . _maybeLog ( uid , type , 'init' ) ;
0 commit comments