Skip to content

Commit 153a29c

Browse files
cjihrigBridgeAR
authored andcommitted
test: refactor test/report/test-report-signal.js
PR-URL: #26446 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Masashi Hirano <shisama07@gmail.com> Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 991ea8a commit 153a29c

1 file changed

Lines changed: 27 additions & 70 deletions

File tree

‎test/report/test-report-signal.js‎

Lines changed: 27 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,36 @@
1+
// Flags: --experimental-report --diagnostic-report-on-signal
12
'use strict';
2-
// Testcase to produce report on signal interrupting a js busy-loop,
3-
// showing it is interruptible.
3+
// Test producing a report via signal.
44
constcommon=require('../common');
55
common.skipIfReportDisabled();
6+
if(common.isWindows)
7+
returncommon.skip('Unsupported on Windows.');
68

7-
if(common.isWindows)returncommon.skip('Unsupported on Windows.');
9+
if(!common.isMainThread)
10+
common.skip('Signal reporting is only supported in the main thread');
811

9-
if(process.argv[2]==='child'){
10-
// Exit on loss of parent process
11-
constexit=()=>process.exit(2);
12-
process.on('disconnect',exit);
12+
constassert=require('assert');
13+
consthelper=require('../common/report');
14+
consttmpdir=require('../common/tmpdir');
1315

14-
functionbusyLoop(){
15-
setInterval(()=>{
16-
constlist=[];
17-
for(leti=0;i<1e3;i++){
18-
for(letj=0;j<1000;j++){
19-
list.push(newMyRecord());
20-
}
21-
for(letk=0;k<1000;k++){
22-
list[k].id+=1;
23-
list[k].account+=2;
24-
}
25-
for(letl=0;l<1000;l++){
26-
list.pop();
27-
}
28-
}
29-
},1000);
30-
}
16+
common.expectWarning('ExperimentalWarning',
17+
'report is an experimental feature. This feature could '+
18+
'change at any time');
19+
tmpdir.refresh();
20+
process.report.directory=tmpdir.path;
3121

32-
functionMyRecord(){
33-
this.name='foo';
34-
this.id=128;
35-
this.account=98454324;
36-
}
37-
process.send('child started',busyLoop);
22+
assert.strictEqual(process.listenerCount('SIGUSR2'),1);
23+
process.kill(process.pid,'SIGUSR2');
3824

25+
// Asynchronously wait for the report. In development, a single setImmediate()
26+
// appears to be enough. Use an async loop to be a bit more robust in case
27+
// platform or machine differences throw off the timing.
28+
(functionvalidate(){
29+
constreports=helper.findReports(process.pid,tmpdir.path);
3930

40-
}else{
41-
consthelper=require('../common/report.js');
42-
constfork=require('child_process').fork;
43-
consttmpdir=require('../common/tmpdir');
44-
tmpdir.refresh();
45-
constassert=require('assert');
46-
if(common.isWindows){
47-
assert.fail('Unsupported on Windows',{skip: true});
48-
return;
49-
}
50-
console.log(tmpdir.path);
51-
constoptions={stdio: 'pipe',encoding: 'utf8',cwd: tmpdir.path};
52-
constchild=fork('--experimental-report',
53-
['--diagnostic-report-on-signal',__filename,'child'],
54-
options);
55-
// Wait for child to indicate it is ready before sending signal
56-
child.on('message',()=>child.kill('SIGUSR2'));
57-
letstderr='';
58-
child.stderr.on('data',(chunk)=>{
59-
stderr+=chunk;
60-
// Terminate the child after the report has been written
61-
if(stderr.includes('Node.js report completed')){
62-
child.kill('SIGTERM');
63-
}
64-
});
65-
child.on('exit',common.mustCall((code,signal)=>{
66-
console.log('child exited');
67-
console.log(stderr);
68-
constreport_msg='No reports found';
69-
constprocess_msg='Process exited unexpectedly';
70-
constsignal_msg='Process exited with unexpected signal';
71-
assert.strictEqual(code,null,process_msg+':'+code);
72-
assert.deepStrictEqual(signal,'SIGTERM',
73-
signal_msg+':'+signal);
74-
constreports=helper.findReports(child.pid,tmpdir.path);
75-
assert.deepStrictEqual(reports.length,1,report_msg);
76-
constreport=reports[0];
77-
helper.validate(report);
78-
}));
79-
}
31+
if(reports.length===0)
32+
returnsetImmediate(validate);
33+
34+
assert.strictEqual(reports.length,1);
35+
helper.validate(reports[0]);
36+
})();

0 commit comments

Comments
 (0)