diff --git a/app/lib/phantomasWrapper.js b/app/lib/phantomasWrapper.js index a33401c..b866fe2 100644 --- a/app/lib/phantomasWrapper.js +++ b/app/lib/phantomasWrapper.js @@ -2,7 +2,7 @@ * Yellow Lab Tools main file */ -var q = require ('q'); +var async = require('async'); var phantomas = require('phantomas'); var PhantomasWrapper = function() { @@ -59,7 +59,28 @@ var PhantomasWrapper = function() { }; // It's time to launch the test!!! - phantomas(task.url, options, callback); + var triesNumber = 3; + + async.retry(triesNumber, function(cb) { + phantomas(task.url, options, function(err, json, results) { + console.log('Returning from Phantomas'); + + // Adding some YellowLabTools errors here + if (!json.metrics.javascriptExecutionTree) { + err = 1001; + } + + if (err) { + console.log('Attempt failed for test id ' + task.testId + '. Error code ' + err); + } + cb(err, {json: json, results: results}); + }); + }, function(err, data) { + if (err) { + console.log('All ' + triesNumber + ' attemps failed for test id ' + task.testId); + } + callback(err, data.json, data.results); + }); }; }; diff --git a/app/lib/testQueue.js b/app/lib/testQueue.js index 82ebd3e..3e32370 100644 --- a/app/lib/testQueue.js +++ b/app/lib/testQueue.js @@ -51,10 +51,13 @@ var testQueue = function() { return position; }; - // Forward testComplete this.testComplete = function(testId) { self.emit('testComplete', testId); }; + + this.testFailed = function(testId) { + self.emit('testFailed', testId); + } }; // extend the EventEmitter class using our Radio class diff --git a/app/node_controllers/launchTestController.js b/app/node_controllers/launchTestController.js index 2b97359..d0c04be 100644 --- a/app/node_controllers/launchTestController.js +++ b/app/node_controllers/launchTestController.js @@ -65,7 +65,7 @@ var launchTestController = function(req, res, testQueue) { ], function(err) { if (err) { - console.log('An error occured while launching the phantomas test : ', err); + console.log('An error occured in the phantomas test: ', err); fs.writeFile(phantomasResultsPath, JSON.stringify({url: url, error: err}, null, 4), function(err) { if (err) { @@ -73,6 +73,7 @@ var launchTestController = function(req, res, testQueue) { console.log(err); } }); + testQueue.testFailed(testId); } else { testQueue.testComplete(testId); } diff --git a/app/node_controllers/waitingQueueSocket.js b/app/node_controllers/waitingQueueSocket.js index 5fdf919..b8fd30f 100644 --- a/app/node_controllers/waitingQueueSocket.js +++ b/app/node_controllers/waitingQueueSocket.js @@ -18,6 +18,13 @@ var waitingQueueSocket = function(socket, testQueue) { } }); + testQueue.on('testFailed', function(id) { + if (testId === id) { + socket.emit('failed'); + console.log('Sending failed event to test id ' + testId); + } + }); + testQueue.on('queueMoving', function() { var positionInQueue = testQueue.indexOf(testId); if (positionInQueue >= 0) { diff --git a/app/node_views/launchTest.html b/app/node_views/launchTest.html index a46c48f..4c005cc 100644 --- a/app/node_views/launchTest.html +++ b/app/node_views/launchTest.html @@ -35,6 +35,11 @@ window.location.replace('/results/' + testId); }); + socket.on('failed', function() { + statusElement.innerHTML = 'Test failed'; + window.location.replace('/results/' + testId); + }); + socket.on('404', function() { statusElement.innerHTML = 'Test not found'; }); diff --git a/app/node_views/results.html b/app/node_views/results.html index 12166fb..2a31763 100644 --- a/app/node_views/results.html +++ b/app/node_views/results.html @@ -7,7 +7,7 @@ - +
@@ -18,13 +18,13 @@