Skip to content

Commit

Permalink
Merge pull request #34 from gmetais/killphantomas
Browse files Browse the repository at this point in the history
Kill the phantomas subprocess before killing YLT
  • Loading branch information
gmetais committed Dec 29, 2014
2 parents 67d0809 + 1920a3e commit a219c1b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
30 changes: 25 additions & 5 deletions lib/tools/phantomas/phantomasWrapper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var async = require('async');
var Q = require('q');
var ps = require('ps-node');
var debug = require('debug')('ylt:phantomaswrapper');
var phantomas = require('phantomas');

Expand Down Expand Up @@ -55,18 +56,34 @@ var PhantomasWrapper = function() {
}
debug('node node_modules/phantomas/bin/phantomas.js --url=' + task.url + optionsString + ' --verbose');

// Kill the application if nothing happens for 10 minutes
// Kill the application if nothing happens
var phantomasPid;
var killer = setTimeout(function() {
debug('Killing the app because the test on %s was launched %d seconds ago', task.url, 3*options.timeout);
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
process.exit(1);
}, 3*options.timeout*60*1000);

// 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);
}

// Then suicide.
process.exit(1);
});
}

}, 5*options.timeout*1000);

// It's time to launch the test!!!
var triesNumber = 2;

async.retry(triesNumber, function(cb) {
phantomas(task.url, options, function(err, json, results) {
var process = phantomas(task.url, options, function(err, json, results) {
debug('Returning from Phantomas');

// Adding some YellowLabTools errors here
Expand All @@ -90,6 +107,9 @@ var PhantomasWrapper = function() {

cb(err, json);
});

phantomasPid = process.pid;

}, function(err, json) {

clearTimeout(killer);
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
"debug": "~2.1.0",
"express": "~4.10.6",
"phantomas": "1.8.0",
"rimraf": "~2.2.8",
"q": "~1.1.2"
"ps-node": "0.0.3",
"q": "~1.1.2",
"rimraf": "~2.2.8"
},
"devDependencies": {
"chai": "^1.10.0",
Expand Down

0 comments on commit a219c1b

Please sign in to comment.