Auto retry twice if test failed
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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';
|
||||
});
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<script src="/bower_components/angular/angular.min.js"></script>
|
||||
<script src="/bower_components/angular-route/angular-route.js"></script>
|
||||
<script src="/public/scripts/app.js"></script>
|
||||
<script src="/public/scripts/resultsController.js"></script>
|
||||
<script src="/public/scripts/resultsCtrl.js"></script>
|
||||
<script src="/public/scripts/filters.js"></script>
|
||||
</head>
|
||||
<body ng-app="Spaghetti" ng-controller="ResultsCtrl">
|
||||
@@ -18,13 +18,13 @@
|
||||
<div class="ng-cloak">
|
||||
<div>Tested url: <a class="testedUrl" href="{{phantomasResults.url}}" target="_blank">{{phantomasResults.url}}</a></div>
|
||||
|
||||
<div ng-if="phantomasResults.error || !javascript">
|
||||
<div ng-if="phantomasResults.error">
|
||||
<h2>Error: {{phantomasResults.error}}</h2>
|
||||
<div ng-if="phantomasResults.error == 252">Phantomas timed out</div>
|
||||
<div ng-if="phantomasResults.error == 253">Phantomas config error</div>
|
||||
<div ng-if="phantomasResults.error == 254">Phantomas failed to load page</div>
|
||||
<div ng-if="phantomasResults.error == 255">Phantomas internal error</div>
|
||||
<div ng-if="!phantomasResults.error && !javascript">Javascript execution tree error</div>
|
||||
<div ng-if="phantomasResults.error == 1001">Javascript execution tree error</div>
|
||||
</div>
|
||||
|
||||
<div ng-if="!phantomasResults.error" class="execution">
|
||||
|
||||
@@ -20,13 +20,13 @@ exports.module = function(phantomas) {
|
||||
phantomas.once('init', function() {
|
||||
phantomas.evaluate(function() {
|
||||
(function(phantomas) {
|
||||
function querySpy(type, query, fnName) {
|
||||
phantomas.emit('domQuery', type, query, fnName); // @desc DOM query has been made
|
||||
function querySpy(type, query, fnName, context) {
|
||||
phantomas.emit('domQuery', type, query, fnName, context); // @desc DOM query has been made
|
||||
}
|
||||
|
||||
phantomas.spy(Document.prototype, 'getElementById', function(id) {
|
||||
phantomas.incrMetric('DOMqueriesById');
|
||||
querySpy('id', '#' + id, 'getElementById');
|
||||
querySpy('id', '#' + id, 'getElementById', '#document');
|
||||
|
||||
phantomas.enterContext({
|
||||
type: 'getElementById',
|
||||
@@ -46,15 +46,17 @@ exports.module = function(phantomas) {
|
||||
function selectorClassNameSpyBefore(className) {
|
||||
/*jshint validthis: true */
|
||||
|
||||
var context = phantomas.getDOMPath(this);
|
||||
|
||||
phantomas.incrMetric('DOMqueriesByClassName');
|
||||
phantomas.addOffender('DOMqueriesByClassName', '.' + className);
|
||||
querySpy('class', '.' + className, 'getElementsByClassName');
|
||||
querySpy('class', '.' + className, 'getElementsByClassName', context);
|
||||
|
||||
phantomas.enterContext({
|
||||
type: 'getElementsByClassName',
|
||||
callDetails: {
|
||||
context: {
|
||||
domElement: phantomas.getDOMPath(this)
|
||||
domElement: context
|
||||
},
|
||||
arguments: ['.' + className]
|
||||
},
|
||||
@@ -70,15 +72,17 @@ exports.module = function(phantomas) {
|
||||
function selectorTagNameSpyBefore(tagName) {
|
||||
/*jshint validthis: true */
|
||||
|
||||
var context = phantomas.getDOMPath(this);
|
||||
|
||||
phantomas.incrMetric('DOMqueriesByTagName');
|
||||
phantomas.addOffender('DOMqueriesByTagName', tagName);
|
||||
querySpy('tag name', tagName, 'getElementsByTagName');
|
||||
querySpy('tag name', tagName, 'getElementsByTagName', context);
|
||||
|
||||
phantomas.enterContext({
|
||||
type: 'getElementsByTagName',
|
||||
callDetails: {
|
||||
context: {
|
||||
domElement: phantomas.getDOMPath(this)
|
||||
domElement: context
|
||||
},
|
||||
arguments: [tagName]
|
||||
},
|
||||
@@ -91,7 +95,7 @@ exports.module = function(phantomas) {
|
||||
phantomas.spy(Element.prototype, 'getElementsByTagName', selectorTagNameSpyBefore, phantomas.leaveContext);
|
||||
|
||||
// selector queries
|
||||
function selectorQuerySpy(selector) {
|
||||
function selectorQuerySpy(selector, context) {
|
||||
phantomas.incrMetric('DOMqueriesByQuerySelectorAll');
|
||||
phantomas.addOffender('DOMqueriesByQuerySelectorAll', selector);
|
||||
querySpy('selector', selector, 'querySelectorAll');
|
||||
@@ -100,13 +104,14 @@ exports.module = function(phantomas) {
|
||||
function selectorQuerySpyBefore(selector) {
|
||||
/*jshint validthis: true */
|
||||
|
||||
selectorQuerySpy(selector);
|
||||
var context = phantomas.getDOMPath(this);
|
||||
selectorQuerySpy(selector, context);
|
||||
|
||||
phantomas.enterContext({
|
||||
type: 'querySelector',
|
||||
callDetails: {
|
||||
context: {
|
||||
domElement: phantomas.getDOMPath(this)
|
||||
domElement: context
|
||||
},
|
||||
arguments: [selector]
|
||||
},
|
||||
@@ -118,13 +123,14 @@ exports.module = function(phantomas) {
|
||||
function selectorAllQuerySpyBefore(selector) {
|
||||
/*jshint validthis: true */
|
||||
|
||||
selectorQuerySpy(selector);
|
||||
var context = phantomas.getDOMPath(this);
|
||||
selectorQuerySpy(selector, context);
|
||||
|
||||
phantomas.enterContext({
|
||||
type: 'querySelectorAll',
|
||||
callDetails: {
|
||||
context: {
|
||||
domElement: phantomas.getDOMPath(this)
|
||||
domElement: context
|
||||
},
|
||||
arguments: [selector]
|
||||
},
|
||||
@@ -140,7 +146,7 @@ exports.module = function(phantomas) {
|
||||
|
||||
|
||||
// count DOM inserts
|
||||
function appendChild(child) {
|
||||
function appendChild(child, context, appended) {
|
||||
/*jshint validthis: true */
|
||||
|
||||
// ignore appending to the node that's not yet added to DOM tree
|
||||
@@ -148,9 +154,6 @@ exports.module = function(phantomas) {
|
||||
return;
|
||||
}
|
||||
|
||||
var destNodePath = phantomas.getDOMPath(this),
|
||||
appendedNodePath = phantomas.getDOMPath(child);
|
||||
|
||||
// don't count elements added to fragments as a DOM inserts (issue #350)
|
||||
// DocumentFragment > div[0]
|
||||
if (destNodePath.indexOf('DocumentFragment') === 0) {
|
||||
@@ -158,23 +161,25 @@ exports.module = function(phantomas) {
|
||||
}
|
||||
|
||||
phantomas.incrMetric('DOMinserts');
|
||||
phantomas.addOffender('DOMinserts', '"%s" appended to "%s"', appendedNodePath, destNodePath);
|
||||
phantomas.addOffender('DOMinserts', '"%s" appended to "%s"', appended, context);
|
||||
|
||||
phantomas.log('DOM insert: node "%s" appended to "%s"', appendedNodePath, destNodePath);
|
||||
phantomas.log('DOM insert: node "%s" appended to "%s"', appended, context);
|
||||
}
|
||||
|
||||
function appendChildSpyBefore(child) {
|
||||
/*jshint validthis: true */
|
||||
|
||||
appendChild(child);
|
||||
var context = phantomas.getDOMPath(this);
|
||||
var appended = phantomas.getDOMPath(child);
|
||||
appendChild(child, context, appended);
|
||||
|
||||
phantomas.enterContext({
|
||||
type: 'appendChild',
|
||||
callDetails: {
|
||||
context: {
|
||||
domElement: phantomas.getDOMPath(this)
|
||||
domElement: context
|
||||
},
|
||||
arguments: [phantomas.getDOMPath(child)]
|
||||
arguments: [appended]
|
||||
},
|
||||
caller: phantomas.getCaller(1),
|
||||
backtrace: phantomas.getBacktrace()
|
||||
@@ -184,15 +189,17 @@ exports.module = function(phantomas) {
|
||||
function insertBeforeSpyBefore(child) {
|
||||
/*jshint validthis: true */
|
||||
|
||||
appendChild(child);
|
||||
var context = phantomas.getDOMPath(this);
|
||||
var appended = phantomas.getDOMPath(child);
|
||||
appendChild(child, context, appended);
|
||||
|
||||
phantomas.enterContext({
|
||||
type: 'insertBefore',
|
||||
callDetails: {
|
||||
context: {
|
||||
domElement: phantomas.getDOMPath(this)
|
||||
domElement: context
|
||||
},
|
||||
arguments: [phantomas.getDOMPath(child)]
|
||||
arguments: [appended]
|
||||
},
|
||||
caller: phantomas.getCaller(1),
|
||||
backtrace: phantomas.getBacktrace()
|
||||
@@ -210,11 +217,18 @@ exports.module = function(phantomas) {
|
||||
var Collection = require('../../../node_modules/phantomas/lib/collection'),
|
||||
DOMqueries = new Collection();
|
||||
|
||||
phantomas.on('domQuery', function(type, query, fnName) {
|
||||
phantomas.log('DOM query: by %s - "%s" (using %s)', type, query, fnName);
|
||||
phantomas.on('domQuery', function(type, query, fnName, context) {
|
||||
phantomas.log('DOM query: by %s - "%s" (using %s on context %s)', type, query, fnName, context);
|
||||
phantomas.incrMetric('DOMqueries');
|
||||
|
||||
DOMqueries.push(type + ' "' + query + '"');
|
||||
var domQuery = {
|
||||
type: type,
|
||||
query: query,
|
||||
fnName: fnName,
|
||||
context: context
|
||||
};
|
||||
|
||||
DOMqueries.push(JSON.stringify(domQuery));
|
||||
});
|
||||
|
||||
phantomas.on('report', function() {
|
||||
|
||||
Reference in New Issue
Block a user