MCPcopy Index your code
hub / github.com/nodejs/node / sanityCheck

Method sanityCheck

test/async-hooks/init-hooks.js:65–126  ·  view source on GitHub ↗
(types)

Source from the content-addressed store, hash-verified

63 }
64
65 sanityCheck(types) {
66 if (types != null && !Array.isArray(types)) types = [ types ];
67
68 function activityString(a) {
69 return util.inspect(a, false, 5, true);
70 }
71
72 const violations = [];
73 let tempActivityString;
74
75 function v(msg) { violations.push(msg); }
76 for (const a of this._activities.values()) {
77 tempActivityString = activityString(a);
78 if (types != null && !types.includes(a.type)) continue;
79
80 if (a.init && a.init.length > 1) {
81 v(`Activity inited twice\n${tempActivityString}` +
82 '\nExpected "init" to be called at most once');
83 }
84 if (a.destroy && a.destroy.length > 1) {
85 v(`Activity destroyed twice\n${tempActivityString}` +
86 '\nExpected "destroy" to be called at most once');
87 }
88 if (a.before && a.after) {
89 if (a.before.length < a.after.length) {
90 v('Activity called "after" without calling "before"\n' +
91 `${tempActivityString}` +
92 '\nExpected no "after" call without a "before"');
93 }
94 if (a.before.some((x, idx) => x > a.after[idx])) {
95 v('Activity had an instance where "after" ' +
96 'was invoked before "before"\n' +
97 `${tempActivityString}` +
98 '\nExpected "after" to be called after "before"');
99 }
100 }
101 if (a.before && a.destroy) {
102 if (a.before.some((x, idx) => x > a.destroy[idx])) {
103 v('Activity had an instance where "destroy" ' +
104 'was invoked before "before"\n' +
105 `${tempActivityString}` +
106 '\nExpected "destroy" to be called after "before"');
107 }
108 }
109 if (a.after && a.destroy) {
110 if (a.after.some((x, idx) => x > a.destroy[idx])) {
111 v('Activity had an instance where "destroy" ' +
112 'was invoked before "after"\n' +
113 `${tempActivityString}` +
114 '\nExpected "destroy" to be called after "after"');
115 }
116 }
117 if (!a.handleIsObject) {
118 v(`No resource object\n${tempActivityString}` +
119 '\nExpected "init" to be called with a resource object');
120 }
121 }
122 if (violations.length) {

Callers 15

onexitFunction · 0.80
onexitFunction · 0.80
onexitFunction · 0.80
onExitFunction · 0.80
onexitFunction · 0.80
onexitFunction · 0.80
onexitFunction · 0.80
onexitFunction · 0.80
onexitFunction · 0.80
onexitFunction · 0.80
onexitFunction · 0.80

Calls 7

includesMethod · 0.80
someMethod · 0.80
vFunction · 0.50
valuesMethod · 0.45
errorMethod · 0.45
joinMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected