|
@@ -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');
|
|
|
|
|
@@ -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
|
|
@@ -90,6 +107,9 @@ var PhantomasWrapper = function() {
|
|
|
|
|
|
cb(err, json);
|
|
|
});
|
|
|
+
|
|
|
+ phantomasPid = process.pid;
|
|
|
+
|
|
|
}, function(err, json) {
|
|
|
|
|
|
clearTimeout(killer);
|