@@ -20,11 +20,21 @@ rmSync(path.join(cwd, 'stdout.log'), { force: true })
2020rmSync ( path . join ( cwd , 'stderr.log' ) , { force : true } )
2121
2222const timeout = setTimeout ( ( ) => {
23- execSync ( 'cat stdout.log' , opts )
24- execSync ( 'cat stderr.log' , opts )
23+ const stdoutLog = path . join ( cwd , 'stdout.log' )
24+ const stderrLog = path . join ( cwd , 'stderr.log' )
25+ if ( existsSync ( stdoutLog ) ) {
26+ execSync ( `cat ${ stdoutLog } ` , opts )
27+ } else {
28+ console . error ( 'stdout.log not found (crashtracker-receiver may not have started)' )
29+ }
30+ if ( existsSync ( stderrLog ) ) {
31+ execSync ( `cat ${ stderrLog } ` , opts )
32+ } else {
33+ console . error ( 'stderr.log not found (crashtracker-receiver may not have started)' )
34+ }
2535
2636 throw new Error ( 'No crash report received before timing out.' )
27- } , 10_000 )
37+ } , 20_000 )
2838
2939let currentTest
3040
@@ -51,20 +61,46 @@ app.post('/telemetry/proxy/api/v2/apmtelemetry', (req, res) => {
5161let PORT
5262
5363function runApp ( script ) {
54- return new Promise ( ( resolve ) => {
55- exec ( `node ${ script } ` , {
64+ return new Promise ( ( resolve , reject ) => {
65+ let closeTimer
66+ let done = false
67+
68+ const child = exec ( `node ${ script } ` , {
5669 ...opts ,
5770 env : { ...process . env , PORT } ,
5871 } )
5972
73+ child . on ( 'error' , ( err ) => {
74+ cleanup ( )
75+ reject ( new Error ( `Child process for "${ script } " failed to start` , { cause : err } ) )
76+ } )
77+
78+ child . on ( 'close' , ( code , signal ) => {
79+ if ( done ) return
80+ // Allow a grace period for the crash report HTTP request to arrive
81+ // after the child process exits (e.g. segfault sends report then dies).
82+ closeTimer = setTimeout ( ( ) => {
83+ const reason = signal ? `signal ${ signal } ` : `exit code ${ code } `
84+ reject ( new Error ( `Child process for "${ script } " exited with ${ reason } before sending a crash report` ) )
85+ } , 5000 )
86+ } )
87+
6088 currentTest = ( logPayload , tags ) => {
89+ cleanup ( )
6190 currentTest = undefined
6291 resolve ( { logPayload, tags } )
6392 }
93+
94+ function cleanup ( ) {
95+ clearTimeout ( closeTimer )
96+ done = true
97+ }
6498 } )
6599}
66100
67101async function testSegfault ( ) {
102+ console . log ( 'Running test: testSegfault' )
103+
68104 const { logPayload, tags } = await runApp ( 'app-seg-fault' )
69105 const stackTrace = JSON . parse ( logPayload . message ) . error . stack . frames
70106 const boomFrame = stackTrace . find ( frame => frame . function ?. toLowerCase ( ) . includes ( 'segfaultify' ) )
@@ -79,6 +115,8 @@ async function testSegfault () {
79115}
80116
81117async function testUnhandledError ( label , script , { expectedType, expectedMessage, expectedFrame } ) {
118+ console . log ( 'Running test: testUnhandledError' , label )
119+
82120 const { logPayload } = await runApp ( script )
83121 const crashReport = JSON . parse ( logPayload . message )
84122
@@ -91,6 +129,8 @@ async function testUnhandledError (label, script, { expectedType, expectedMessag
91129}
92130
93131async function testUnhandledNonError ( label , script , { expectedFallbackType, expectedValue } ) {
132+ console . log ( 'Running test: testUnhandledNonError' , label )
133+
94134 const { logPayload } = await runApp ( script )
95135 const crashReport = JSON . parse ( logPayload . message )
96136
0 commit comments