-
Notifications
You must be signed in to change notification settings - Fork 28.2k
/
test.js
50 lines (43 loc) · 1.23 KB
/
test.js
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
'use strict';
const common = require('../../common');
const assert = require('assert');
const path = require('path');
const spawnSync = require('child_process').spawnSync;
const binding = path.resolve(__dirname, `./build/${common.buildType}/binding`);
Object.defineProperty(globalThis, 'interrupt', {
get: () => {
return null;
},
set: () => {
throw new Error('should not calling into js');
},
});
if (process.argv[2] === 'child-busyloop') {
(function childMain() {
const addon = require(binding);
addon[process.argv[3]]();
while (true) {
/** wait for interrupt */
}
})();
return;
}
if (process.argv[2] === 'child-idle') {
(function childMain() {
const addon = require(binding);
addon[process.argv[3]]();
// wait for interrupt
setTimeout(() => {}, 10_000_000);
})();
return;
}
for (const type of ['busyloop', 'idle']) {
{
const child = spawnSync(process.execPath, [ __filename, `child-${type}`, 'scheduleInterrupt' ]);
assert.strictEqual(child.status, 0, `${type} should exit with code 0`);
}
{
const child = spawnSync(process.execPath, [ __filename, `child-${type}`, 'ScheduleInterruptWithJS' ]);
assert(common.nodeProcessAborted(child.status, child.signal));
}
}