Skip to content

Commit ebbc070

Browse files
authored
ci: implement timeout for run-automated (#9209)
* ci: implement timeout for run-automated * fix: assign timeout_id
1 parent d871765 commit ebbc070

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

tools/scripts/run-automated.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,36 @@
77
const spawn = require('child_process').spawn
88
const kill = require('tree-kill');
99

10+
const TIMEOUT_MS = 5 * 60 * 1000; // 5 minutes
11+
1012
const spawned_process = spawn('npm', ['start', `apps.automated.${process.argv[2]}`], {
1113
stdio: ['inherit', 'pipe', 'pipe']
1214
})
13-
1415
const {stdout, stderr} = spawned_process
1516

1617
stdout.pipe(process.stdout)
1718
stderr.pipe(process.stderr)
1819

1920
let lineBuffer = []
21+
let timeout_id;
22+
23+
function exit(code) {
24+
kill(spawned_process.pid)
25+
process.exit(code)
26+
}
27+
28+
function onTimeout() {
29+
console.log(`Tests TIMEOUT (${TIMEOUT_MS}ms)`)
30+
exit(1)
31+
}
32+
33+
function healthCheck() {
34+
clearTimeout(timeout_id)
35+
timeout_id = setTimeout(onTimeout, TIMEOUT_MS)
36+
}
2037

2138
stdout.on('data', data => {
39+
healthCheck();
2240
const line = data.toString();
2341

2442
// start buffering lines when tests are complete
@@ -29,8 +47,6 @@ stdout.on('data', data => {
2947
if(line.includes('Tests EOF!')) {
3048
let ok = lineBuffer.join('\n').includes('OK, 0 failed')
3149
console.log(ok ? 'Tests PASSED' : 'Tests FAILED');
32-
kill(spawned_process.pid)
33-
process.exit(ok ? 0 : 1)
50+
exit(ok ? 0 : 1)
3451
}
3552
})
36-

0 commit comments

Comments
 (0)