Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kill the phantomas subprocess before killing YLT #34

Merged
merged 1 commit into from
Dec 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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