From 090a53b95ae18078cbb19b1a6684ef3c1bab6792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20M=C3=A9tais?= Date: Mon, 25 May 2015 15:57:01 +0200 Subject: [PATCH] Killing a Phantomas process will not kill YLT anymore --- lib/server/datastores/runsDatastore.js | 6 ++++ lib/tools/phantomas/phantomasWrapper.js | 37 +++++++++++++++++++------ 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/lib/server/datastores/runsDatastore.js b/lib/server/datastores/runsDatastore.js index 15b4ada..8104b68 100644 --- a/lib/server/datastores/runsDatastore.js +++ b/lib/server/datastores/runsDatastore.js @@ -58,6 +58,9 @@ function RunsDatastore() { var errorMessage; switch(err) { + case '1': + errorMessage = "Error 1: unknown error"; + break; case '252': errorMessage = "Error 252: page timeout in Phantomas"; break; @@ -76,6 +79,9 @@ function RunsDatastore() { case '1002': errorMessage = "Error 1002: missing Phantomas metrics"; break; + case '1003': + errorMessage = "Error 1003: Phantomas not returning"; + break; default: errorMessage = err; } diff --git a/lib/tools/phantomas/phantomasWrapper.js b/lib/tools/phantomas/phantomasWrapper.js index f4d85a0..1e2a74a 100644 --- a/lib/tools/phantomas/phantomasWrapper.js +++ b/lib/tools/phantomas/phantomasWrapper.js @@ -19,6 +19,7 @@ var PhantomasWrapper = function() { var options = { + // Cusomizable options 'timeout': task.options.timeout || 45, 'js-deep-analysis': task.options.jsDeepAnalysis || false, @@ -75,34 +76,52 @@ var PhantomasWrapper = function() { } debug('node node_modules/phantomas/bin/phantomas.js --url=' + task.url + optionsString + ' --verbose'); - // Kill the application if nothing happens + var phantomasPid; + var isKilled = false; + + // Kill phantomas if nothing happens var killer = setTimeout(function() { - debug('Killing the app because the test on %s was launched %d seconds ago', task.url, 5*options.timeout); - // If in server mode, forever will restart the server + console.log('Killing phantomas because the test on ' + task.url + ' was launched ' + 5*options.timeout + ' seconds ago'); - // Kill the Phantomas process first if (phantomasPid) { ps.kill(phantomasPid, function(err) { + if (err) { debug('Could not kill Phantomas process %s', phantomasPid); - } - else { - debug('Phantomas process %s was correctly killed', phantomasPid); + + // Suicide + process.exit(1); + // If in server mode, forever will restart the server } - // Then suicide. - process.exit(1); + debug('Phantomas process %s was correctly killed', phantomasPid); + + // Then mark the test as failed + // Error 1003 = Phantomas not answering + deferred.reject(1003); + isKilled = true; }); + } else { + // Suicide + process.exit(1); } }, 5*options.timeout*1000); + // It's time to launch the test!!! var triesNumber = 2; async.retry(triesNumber, function(cb) { var process = phantomas(task.url, options, function(err, json, results) { + + if (isKilled) { + debug('Process was killed, too late Phantomas, sorry...'); + return; + } + + debug('Returning from Phantomas'); // Adding some YellowLabTools errors here