This repository was archived by the owner on Jun 18, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathtest-signal.js
More file actions
70 lines (62 loc) · 1.97 KB
/
test-signal.js
File metadata and controls
70 lines (62 loc) · 1.97 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
'use strict';
// Testcase to produce report on signal interrupting a js busy-loop,
// showing it is interruptible.
if (process.argv[2] === 'child') {
require('../');
// Exit on loss of parent process
process.on('disconnect', () => process.exit(2));
// tap with coverage enabled installs signal handlers that prevents the
// signal from causing the process to exit. Remove them.
process.removeAllListeners('SIGTERM');
function busyLoop() {
var list = [];
for (var i = 0; i < 1e10; i++) {
for (var j = 0; j < 1000; j++) {
list.push(new MyRecord());
}
for (var k = 0; k < 1000; k++) {
list[k].id += 1;
list[k].account += 2;
}
for (var l = 0; l < 1000; l++) {
list.pop();
}
}
}
function MyRecord() {
this.name = 'foo';
this.id = 128;
this.account = 98454324;
}
process.send('child started', busyLoop);
} else {
const common = require('./common.js');
const fork = require('child_process').fork;
const tap = require('tap');
if (common.isWindows()) {
tap.fail('Unsupported on Windows', { skip: true });
return;
}
const child = fork(__filename, ['child'], { silent: true });
// Wait for child to indicate it is ready before sending signal
child.on('message', () => child.kill('SIGUSR2'));
var stderr = '';
child.stderr.on('data', (chunk) => {
stderr += chunk;
// Terminate the child after the report has been written
if (stderr.includes('Node.js report completed')) {
child.kill('SIGTERM');
}
});
child.on('exit', (code, signal) => {
tap.plan(4);
tap.equal(code, null, 'Process should not exit cleanly');
tap.equal(signal, 'SIGTERM', 'Process should exit with expected signal');
const reports = common.findReports(child.pid);
tap.equal(reports.length, 1, 'Found reports ' + reports);
const report = reports[0];
common.validate(tap, report, {pid: child.pid,
commandline: child.spawnargs.join(' ')
});
});
}