Bug 786258 - Catch exceptions thrown in endurance tests so incomplete reports can be sent. r=hskupin mozilla-beta
authorDave Hunt <dhunt@mozilla.com>
Wed, 05 Sep 2012 16:47:48 +0100
branchmozilla-beta
changeset 2586 a9b6d4e43e6498e33b88f13082c298ac4a901f47
parent 2579 4026325038f03b4f3ed3bf38b5fa2997e0ecde07
child 2589 211f23daebd9b38c512aca7216809aa26c582842
push id2420
push userdhunt@mozilla.com
push dateMon, 10 Sep 2012 12:34:19 +0000
reviewershskupin
bugs786258
Bug 786258 - Catch exceptions thrown in endurance tests so incomplete reports can be sent. r=hskupin
lib/endurance.js
--- a/lib/endurance.js
+++ b/lib/endurance.js
@@ -57,41 +57,64 @@ EnduranceManager.prototype = {
    *
    * @returns {Number} Current entity
    */
   get currentEntity() {
     return this._currentEntity;
   },
 
   /**
+   * Get the number of iterations
+   *
+   * @returns {Number} Number of iterations
+   */
+  get iterations() {
+    return this._iterations;
+  },
+
+  /**
+   * Get the current iteration
+   *
+   * @returns {Number} Current iteration
+   */
+  get currentIteration() {
+    return this._currentIteration;
+  },
+
+  /**
    * Run endurance test
    *
    * @param {function} callback
    *        Callback function to call
    */
   run : function endurance_run(callback) {
     var _testResults = {
       testMethod : frame.events.currentTest.__name__,
       testFile : frame.events.currentModule.__file__,
       iterations : [ ]
     };
 
-    for (var i = 0; i < this._iterations; i++) {
-      this._currentIteration = i + 1;
-      this._controller.sleep(this._delay);
-      this._perfTracer.addCheckpoint("Start iteration");
+    try {
+      for (var i = 0; i < this._iterations; i++) {
+        this._currentIteration = i + 1;
+        this._controller.sleep(this._delay);
+        this._perfTracer.addCheckpoint("Start iteration");
 
-      // Run the main test method
-      callback();
-
-      this._perfTracer.addCheckpoint("End iteration");
-      _testResults.iterations.push({"checkpoints" : this._perfTracer._log});
-      this._perfTracer.clearLog();
+        try {
+          // Run the main test method
+          callback();
+          this._perfTracer.addCheckpoint("End iteration");
+        } finally {
+          _testResults.iterations.push({"checkpoints" : this._perfTracer._log});
+          this._perfTracer.clearLog();
+        }
+      }
+    } finally {
+      frame.events.fireEvent('enduranceResults', _testResults);
     }
-    frame.events.fireEvent('enduranceResults', _testResults)
   },
 
   /**
    * Loop through each of the entities
    *
    * @param {function} callback
    *        Callback function to call
    */