Преглед на файлове

Auto retry twice if test failed

Gaël Métais преди 11 години
родител
ревизия
3001009d3f

+ 23 - 2
app/lib/phantomasWrapper.js

@@ -2,7 +2,7 @@
  * Yellow Lab Tools main file
  * Yellow Lab Tools main file
  */
  */
 
 
-var q               = require ('q');
+var async           = require('async');
 var phantomas       = require('phantomas');
 var phantomas       = require('phantomas');
 
 
 var PhantomasWrapper = function() {
 var PhantomasWrapper = function() {
@@ -59,7 +59,28 @@ var PhantomasWrapper = function() {
         };
         };
 
 
         // It's time to launch the test!!!
         // 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);
+        });
 
 
     };
     };
 };
 };

+ 4 - 1
app/lib/testQueue.js

@@ -51,10 +51,13 @@ var testQueue = function() {
         return position;
         return position;
     };
     };
 
 
-    // Forward testComplete
     this.testComplete = function(testId) {
     this.testComplete = function(testId) {
         self.emit('testComplete', testId);
         self.emit('testComplete', testId);
     };
     };
+
+    this.testFailed = function(testId) {
+        self.emit('testFailed', testId);
+    }
 };
 };
 
 
 // extend the EventEmitter class using our Radio class
 // extend the EventEmitter class using our Radio class

+ 2 - 1
app/node_controllers/launchTestController.js

@@ -65,7 +65,7 @@ var launchTestController = function(req, res, testQueue) {
 
 
     ], function(err) {
     ], function(err) {
         if (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) {
             fs.writeFile(phantomasResultsPath, JSON.stringify({url: url, error: err}, null, 4), function(err) {
                 if (err) {
                 if (err) {
@@ -73,6 +73,7 @@ var launchTestController = function(req, res, testQueue) {
                     console.log(err);
                     console.log(err);
                 }
                 }
             });
             });
+            testQueue.testFailed(testId);
         } else {
         } else {
             testQueue.testComplete(testId);
             testQueue.testComplete(testId);
         }
         }

+ 7 - 0
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() {
         testQueue.on('queueMoving', function() {
             var positionInQueue = testQueue.indexOf(testId);
             var positionInQueue = testQueue.indexOf(testId);
             if (positionInQueue >= 0) {
             if (positionInQueue >= 0) {

+ 5 - 0
app/node_views/launchTest.html

@@ -35,6 +35,11 @@
             window.location.replace('/results/' + testId);
             window.location.replace('/results/' + testId);
         });
         });
 
 
+        socket.on('failed', function() {
+            statusElement.innerHTML = 'Test failed';
+            window.location.replace('/results/' + testId);
+        });
+
         socket.on('404', function() {
         socket.on('404', function() {
             statusElement.innerHTML = 'Test not found';
             statusElement.innerHTML = 'Test not found';
         });
         });

+ 3 - 3
app/node_views/results.html

@@ -7,7 +7,7 @@
     <script src="/bower_components/angular/angular.min.js"></script>
     <script src="/bower_components/angular/angular.min.js"></script>
     <script src="/bower_components/angular-route/angular-route.js"></script>
     <script src="/bower_components/angular-route/angular-route.js"></script>
     <script src="/public/scripts/app.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>
     <script src="/public/scripts/filters.js"></script>
 </head>
 </head>
 <body ng-app="Spaghetti" ng-controller="ResultsCtrl">
 <body ng-app="Spaghetti" ng-controller="ResultsCtrl">
@@ -18,13 +18,13 @@
     <div class="ng-cloak">
     <div class="ng-cloak">
         <div>Tested url: <a class="testedUrl" href="{{phantomasResults.url}}" target="_blank">{{phantomasResults.url}}</a></div>
         <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>
             <h2>Error: {{phantomasResults.error}}</h2>
             <div ng-if="phantomasResults.error == 252">Phantomas timed out</div>
             <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 == 253">Phantomas config error</div>
             <div ng-if="phantomasResults.error == 254">Phantomas failed to load page</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 == 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>
 
 
         <div ng-if="!phantomasResults.error" class="execution">
         <div ng-if="!phantomasResults.error" class="execution">

+ 0 - 0
app/public/scripts/resultsController.js → app/public/scripts/resultsCtrl.js


+ 41 - 27
phantomas_custom/modules/domQYLT/domQYLT.js

@@ -20,13 +20,13 @@ exports.module = function(phantomas) {
     phantomas.once('init', function() {
     phantomas.once('init', function() {
         phantomas.evaluate(function() {
         phantomas.evaluate(function() {
             (function(phantomas) {
             (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.spy(Document.prototype, 'getElementById', function(id) {
                     phantomas.incrMetric('DOMqueriesById');
                     phantomas.incrMetric('DOMqueriesById');
-                    querySpy('id', '#' + id, 'getElementById');
+                    querySpy('id', '#' + id, 'getElementById', '#document');
 
 
                     phantomas.enterContext({
                     phantomas.enterContext({
                         type: 'getElementById',
                         type: 'getElementById',
@@ -46,15 +46,17 @@ exports.module = function(phantomas) {
                 function selectorClassNameSpyBefore(className) {
                 function selectorClassNameSpyBefore(className) {
                     /*jshint validthis: true */
                     /*jshint validthis: true */
 
 
+                    var context = phantomas.getDOMPath(this);
+
                     phantomas.incrMetric('DOMqueriesByClassName');
                     phantomas.incrMetric('DOMqueriesByClassName');
                     phantomas.addOffender('DOMqueriesByClassName', '.' + className);
                     phantomas.addOffender('DOMqueriesByClassName', '.' + className);
-                    querySpy('class', '.' + className, 'getElementsByClassName');
+                    querySpy('class', '.' + className, 'getElementsByClassName', context);
 
 
                     phantomas.enterContext({
                     phantomas.enterContext({
                         type: 'getElementsByClassName',
                         type: 'getElementsByClassName',
                         callDetails: {
                         callDetails: {
                             context: {
                             context: {
-                                domElement: phantomas.getDOMPath(this)
+                                domElement: context
                             },
                             },
                             arguments: ['.' + className]
                             arguments: ['.' + className]
                         },
                         },
@@ -70,15 +72,17 @@ exports.module = function(phantomas) {
                 function selectorTagNameSpyBefore(tagName) {
                 function selectorTagNameSpyBefore(tagName) {
                     /*jshint validthis: true */
                     /*jshint validthis: true */
 
 
+                    var context = phantomas.getDOMPath(this);
+
                     phantomas.incrMetric('DOMqueriesByTagName');
                     phantomas.incrMetric('DOMqueriesByTagName');
                     phantomas.addOffender('DOMqueriesByTagName', tagName);
                     phantomas.addOffender('DOMqueriesByTagName', tagName);
-                    querySpy('tag name', tagName, 'getElementsByTagName');
+                    querySpy('tag name', tagName, 'getElementsByTagName', context);
 
 
                     phantomas.enterContext({
                     phantomas.enterContext({
                         type: 'getElementsByTagName',
                         type: 'getElementsByTagName',
                         callDetails: {
                         callDetails: {
                             context: {
                             context: {
-                                domElement: phantomas.getDOMPath(this)
+                                domElement: context
                             },
                             },
                             arguments: [tagName]
                             arguments: [tagName]
                         },
                         },
@@ -91,7 +95,7 @@ exports.module = function(phantomas) {
                 phantomas.spy(Element.prototype, 'getElementsByTagName', selectorTagNameSpyBefore, phantomas.leaveContext);
                 phantomas.spy(Element.prototype, 'getElementsByTagName', selectorTagNameSpyBefore, phantomas.leaveContext);
 
 
                 // selector queries
                 // selector queries
-                function selectorQuerySpy(selector) {
+                function selectorQuerySpy(selector, context) {
                     phantomas.incrMetric('DOMqueriesByQuerySelectorAll');
                     phantomas.incrMetric('DOMqueriesByQuerySelectorAll');
                     phantomas.addOffender('DOMqueriesByQuerySelectorAll', selector);
                     phantomas.addOffender('DOMqueriesByQuerySelectorAll', selector);
                     querySpy('selector', selector, 'querySelectorAll');
                     querySpy('selector', selector, 'querySelectorAll');
@@ -100,13 +104,14 @@ exports.module = function(phantomas) {
                 function selectorQuerySpyBefore(selector) {
                 function selectorQuerySpyBefore(selector) {
                     /*jshint validthis: true */
                     /*jshint validthis: true */
 
 
-                    selectorQuerySpy(selector);
+                    var context = phantomas.getDOMPath(this);
+                    selectorQuerySpy(selector, context);
 
 
                     phantomas.enterContext({
                     phantomas.enterContext({
                         type: 'querySelector',
                         type: 'querySelector',
                         callDetails: {
                         callDetails: {
                             context: {
                             context: {
-                                domElement: phantomas.getDOMPath(this)
+                                domElement: context
                             },
                             },
                             arguments: [selector]
                             arguments: [selector]
                         },
                         },
@@ -118,13 +123,14 @@ exports.module = function(phantomas) {
                 function selectorAllQuerySpyBefore(selector) {
                 function selectorAllQuerySpyBefore(selector) {
                     /*jshint validthis: true */
                     /*jshint validthis: true */
 
 
-                    selectorQuerySpy(selector);
+                    var context = phantomas.getDOMPath(this);
+                    selectorQuerySpy(selector, context);
 
 
                     phantomas.enterContext({
                     phantomas.enterContext({
                         type: 'querySelectorAll',
                         type: 'querySelectorAll',
                         callDetails: {
                         callDetails: {
                             context: {
                             context: {
-                                domElement: phantomas.getDOMPath(this)
+                                domElement: context
                             },
                             },
                             arguments: [selector]
                             arguments: [selector]
                         },
                         },
@@ -140,7 +146,7 @@ exports.module = function(phantomas) {
 
 
 
 
                 // count DOM inserts
                 // count DOM inserts
-                function appendChild(child) {
+                function appendChild(child, context, appended) {
                     /*jshint validthis: true */
                     /*jshint validthis: true */
 
 
                     // ignore appending to the node that's not yet added to DOM tree
                     // ignore appending to the node that's not yet added to DOM tree
@@ -148,9 +154,6 @@ exports.module = function(phantomas) {
                         return;
                         return;
                     }
                     }
 
 
-                    var destNodePath = phantomas.getDOMPath(this),
-                        appendedNodePath = phantomas.getDOMPath(child);
-
                     // don't count elements added to fragments as a DOM inserts (issue #350)
                     // don't count elements added to fragments as a DOM inserts (issue #350)
                     // DocumentFragment > div[0]
                     // DocumentFragment > div[0]
                     if (destNodePath.indexOf('DocumentFragment') === 0) {
                     if (destNodePath.indexOf('DocumentFragment') === 0) {
@@ -158,23 +161,25 @@ exports.module = function(phantomas) {
                     }
                     }
 
 
                     phantomas.incrMetric('DOMinserts');
                     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) {
                 function appendChildSpyBefore(child) {
                     /*jshint validthis: true */
                     /*jshint validthis: true */
 
 
-                    appendChild(child);
+                    var context = phantomas.getDOMPath(this);
+                    var appended = phantomas.getDOMPath(child);
+                    appendChild(child, context, appended);
 
 
                     phantomas.enterContext({
                     phantomas.enterContext({
                         type: 'appendChild',
                         type: 'appendChild',
                         callDetails: {
                         callDetails: {
                             context: {
                             context: {
-                                domElement: phantomas.getDOMPath(this)
+                                domElement: context
                             },
                             },
-                            arguments: [phantomas.getDOMPath(child)]
+                            arguments: [appended]
                         },
                         },
                         caller: phantomas.getCaller(1),
                         caller: phantomas.getCaller(1),
                         backtrace: phantomas.getBacktrace()
                         backtrace: phantomas.getBacktrace()
@@ -184,15 +189,17 @@ exports.module = function(phantomas) {
                 function insertBeforeSpyBefore(child) {
                 function insertBeforeSpyBefore(child) {
                     /*jshint validthis: true */
                     /*jshint validthis: true */
                     
                     
-                    appendChild(child);
+                    var context = phantomas.getDOMPath(this);
+                    var appended = phantomas.getDOMPath(child);
+                    appendChild(child, context, appended);
 
 
                     phantomas.enterContext({
                     phantomas.enterContext({
                         type: 'insertBefore',
                         type: 'insertBefore',
                         callDetails: {
                         callDetails: {
                             context: {
                             context: {
-                                domElement: phantomas.getDOMPath(this)
+                                domElement: context
                             },
                             },
-                            arguments: [phantomas.getDOMPath(child)]
+                            arguments: [appended]
                         },
                         },
                         caller: phantomas.getCaller(1),
                         caller: phantomas.getCaller(1),
                         backtrace: phantomas.getBacktrace()
                         backtrace: phantomas.getBacktrace()
@@ -210,11 +217,18 @@ exports.module = function(phantomas) {
     var Collection = require('../../../node_modules/phantomas/lib/collection'),
     var Collection = require('../../../node_modules/phantomas/lib/collection'),
         DOMqueries = new 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');
         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() {
     phantomas.on('report', function() {