From 817b8d290637bd9f020cf4e93185c355080ca2e4 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Thu, 30 Oct 2014 21:43:47 +0000 Subject: [PATCH] Improve handling of forked processes in tests. Closes #4277 - Increase the wait time for forked processes to spin up. - If we give up on waiting for a forked process, send it a kill signal so if it comes alive later it doesn't sit in the background forever. - Fail fast if test setup fails instead of waiting for the timeout. --- core/test/functional/routes/admin_test.js | 4 ++++ core/test/functional/routes/frontend_test.js | 2 ++ core/test/utils/fork.js | 10 +++++++--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/core/test/functional/routes/admin_test.js b/core/test/functional/routes/admin_test.js index 12cb9b13b5..7e364b4b03 100644 --- a/core/test/functional/routes/admin_test.js +++ b/core/test/functional/routes/admin_test.js @@ -126,6 +126,8 @@ describe('Admin Routing', function () { after(function (done) { if (forkedGhost) { forkedGhost.kill(done); + } else { + done(new Error('No forked ghost process exists, test setup must have failed.')); } }); @@ -162,6 +164,8 @@ describe('Admin Routing', function () { after(function (done) { if (forkedGhost) { forkedGhost.kill(done); + } else { + done(new Error('No forked ghost process exists, test setup must have failed.')); } }); diff --git a/core/test/functional/routes/frontend_test.js b/core/test/functional/routes/frontend_test.js index 79a5e9fafb..dd31de4cbf 100644 --- a/core/test/functional/routes/frontend_test.js +++ b/core/test/functional/routes/frontend_test.js @@ -707,6 +707,8 @@ describe('Frontend Routing', function () { after(function (done) { if (forkedGhost) { forkedGhost.kill(done); + } else { + done(new Error('No forked ghost process exists, test setup must have failed.')); } }); diff --git a/core/test/utils/fork.js b/core/test/utils/fork.js index 4d69af4b87..218f219fe4 100644 --- a/core/test/utils/fork.js +++ b/core/test/utils/fork.js @@ -96,7 +96,8 @@ function forkGhost(newConfig, envName) { /*jshint unused:false*/ pingTries = pingTries + 1; // continue checking - if (pingTries >= 20 && pingStop()) { + if (pingTries >= 50 && pingStop()) { + child.kill(); reject(new Error('Timed out waiting for child process')); } }); @@ -105,11 +106,14 @@ function forkGhost(newConfig, envName) { child.on('exit', function (code, signal) { /*jshint unused:false*/ child.exited = true; + + fs.unlink(newConfigFile, function () { + // swallow any errors -- file may not exist if fork() failed + }); + if (pingStop()) { reject(new Error('Child process exit code: ' + code)); } - // cleanup the temporary config file - fs.unlink(newConfigFile); }); // override kill() to have an async callback