From 7d2c0d538b74e76f47bc6ec2281f6b678684f60c Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Fri, 24 Jul 2015 18:27:03 -0700 Subject: [PATCH] Not clear why, but child processes are not killed --- e2etestrunner.js | 26 ++++++++++++++++++++++---- package.json | 3 ++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/e2etestrunner.js b/e2etestrunner.js index 0975370..2384b29 100755 --- a/e2etestrunner.js +++ b/e2etestrunner.js @@ -9,6 +9,7 @@ var debug = require('debug')('e2e:runner'), semver = require('semver'), mailer = require('./mailer.js'), superagent = require('superagent'), + terminate = require('terminate'), util = require('util'); // override debug.log to print only as console.log @@ -16,11 +17,21 @@ debug.log = console.log.bind(console); var gLastModified = null; // do not use etag since it only hashes body. touching file to rerun tests is nice var gLatestBoxVersion = null; // for sending mail +var gNpmTest = null; + +function cleanExit() { + if (gNpmTest) { + debug('Terminating child test process %s', gNpmTest.pid); + terminate(gNpmTest.pid, process.exit); + gNpmTest = null; + } else { + debug('No child test process to terminate'); + process.exit(); + } +} function start() { - runTestsIfNeeded(function () { - setTimeout(start, 60 * 1000); - }); + setTimeout(runTestsIfNeeded.bind(null, start), 60 * 1000); } function runTestsIfNeeded(callback) { @@ -73,7 +84,8 @@ function runTests(latestETag, latestBoxVersion, callback) { debug('Running tests for %s', topic); - shell.system('e2etestrunner', 'npm test', function (error, stdout, stderr) { + gNpmTest = shell.system('e2etestrunner', 'npm test', function (error, stdout, stderr) { + gNpmTest = null; debug('Final test result', error); mailer.sendEndToEndTestResult(topic, stdout ? stdout.toString('utf8') : '', stderr ? stderr.toString('utf8') : '', function () { }); @@ -82,4 +94,10 @@ function runTests(latestETag, latestBoxVersion, callback) { } debug('e2etest started.'); + +process.on('exit', cleanExit); +process.on('SIGINT', cleanExit); // catch ctrl-c +process.on('SIGTERM', cleanExit); // catch kill +process.on('uncaughtException', cleanExit); + start(); diff --git a/package.json b/package.json index 177a4d3..fa69fc6 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "stripe": "^3.5.0", "superagent": "^1.2.0", "superagent-sync": "^0.1.0", - "supererror": "^0.7.0" + "supererror": "^0.7.0", + "terminate": "^1.0.5" } }