From ebbc07040ca1782244b01f45cc04963581c50bf9 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Thu, 11 Feb 2021 11:18:15 +0100 Subject: [PATCH] ci: implement timeout for run-automated (#9209) * ci: implement timeout for run-automated * fix: assign timeout_id --- tools/scripts/run-automated.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/tools/scripts/run-automated.js b/tools/scripts/run-automated.js index 8c67329a1..75b544d90 100644 --- a/tools/scripts/run-automated.js +++ b/tools/scripts/run-automated.js @@ -7,18 +7,36 @@ const spawn = require('child_process').spawn const kill = require('tree-kill'); +const TIMEOUT_MS = 5 * 60 * 1000; // 5 minutes + const spawned_process = spawn('npm', ['start', `apps.automated.${process.argv[2]}`], { stdio: ['inherit', 'pipe', 'pipe'] }) - const {stdout, stderr} = spawned_process stdout.pipe(process.stdout) stderr.pipe(process.stderr) let lineBuffer = [] +let timeout_id; + +function exit(code) { + kill(spawned_process.pid) + process.exit(code) +} + +function onTimeout() { + console.log(`Tests TIMEOUT (${TIMEOUT_MS}ms)`) + exit(1) +} + +function healthCheck() { + clearTimeout(timeout_id) + timeout_id = setTimeout(onTimeout, TIMEOUT_MS) +} stdout.on('data', data => { + healthCheck(); const line = data.toString(); // start buffering lines when tests are complete @@ -29,8 +47,6 @@ stdout.on('data', data => { if(line.includes('Tests EOF!')) { let ok = lineBuffer.join('\n').includes('OK, 0 failed') console.log(ok ? 'Tests PASSED' : 'Tests FAILED'); - kill(spawned_process.pid) - process.exit(ok ? 0 : 1) + exit(ok ? 0 : 1) } }) -