Bug 845966 - Detect more errors during FHR initialization; r=rnewman, a=bajaj
authorGregory Szorc <gps@mozilla.com>
Wed, 27 Feb 2013 16:52:29 -0800
changeset 132260 7f479a1288992390fbd13986003c81dd7c56e6f8
parent 132259 28f74a0a851baab80ca12f465c3626fd06aa80b3
child 132261 7a02f7b0b10f20ab271aa07f994f89c3567ce22b
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman, bajaj
bugs845966
milestone21.0a2
Bug 845966 - Detect more errors during FHR initialization; r=rnewman, a=bajaj
services/healthreport/healthreporter.jsm
services/healthreport/modules-testing/utils.jsm
services/healthreport/tests/xpcshell/test_healthreporter.js
--- a/services/healthreport/healthreporter.jsm
+++ b/services/healthreport/healthreporter.jsm
@@ -231,27 +231,31 @@ AbstractHealthReporter.prototype = Objec
       return;
     }
 
     this._log.info("Request to shut down.");
 
     this._initialized = false;
     this._shutdownRequested = true;
 
-    if (this._collectorInProgress) {
-      this._log.warn("Collector is in progress of initializing. Waiting to finish.");
-      return;
-    }
+    if (this._initializeHadError) {
+      this._log.warn("Initialization had error. Shutting down immediately.");
+    } else {
+      if (this._collectorInProgress) {
+        this._log.warn("Collector is in progress of initializing. Waiting to finish.");
+        return;
+      }
 
-    // If storage is in the process of initializing, we need to wait for it
-    // to finish before continuing. The initialization process will call us
-    // again once storage has initialized.
-    if (this._storageInProgress) {
-      this._log.warn("Storage is in progress of initializing. Waiting to finish.");
-      return;
+      // If storage is in the process of initializing, we need to wait for it
+      // to finish before continuing. The initialization process will call us
+      // again once storage has initialized.
+      if (this._storageInProgress) {
+        this._log.warn("Storage is in progress of initializing. Waiting to finish.");
+        return;
+      }
     }
 
     this._log.warn("Initiating main shutdown procedure.");
 
     // Everything from here must only be performed once or else race conditions
     // could occur.
 
     TelemetryStopwatch.start(TELEMETRY_SHUTDOWN, this);
--- a/services/healthreport/modules-testing/utils.jsm
+++ b/services/healthreport/modules-testing/utils.jsm
@@ -231,16 +231,26 @@ InspectedHealthReporter.prototype = {
   _onStorageCreated: function (storage) {
     if (this.onStorageCreated) {
       this.onStorageCreated(storage);
     }
 
     return HealthReporter.prototype._onStorageCreated.call(this, storage);
   },
 
+  _initializeCollector: function () {
+    for (let result of HealthReporter.prototype._initializeCollector.call(this)) {
+      yield result;
+    }
+
+    if (this.onInitializeCollectorFinished) {
+      this.onInitializeCollectorFinished();
+    }
+  },
+
   _onCollectorInitialized: function () {
     if (this.onCollectorInitialized) {
       this.onCollectorInitialized();
     }
 
     return HealthReporter.prototype._onCollectorInitialized.call(this);
   },
 
--- a/services/healthreport/tests/xpcshell/test_healthreporter.js
+++ b/services/healthreport/tests/xpcshell/test_healthreporter.js
@@ -149,16 +149,31 @@ add_task(function test_shutdown_collecto
   };
 
   // This will hang if shutdown logic is busted.
   reporter._waitForShutdown();
   do_check_eq(reporter.collectorShutdownCount, 1);
   do_check_eq(reporter.storageCloseCount, 1);
 });
 
+// Simulates an error during collector initialization and verifies we shut down.
+add_task(function test_shutdown_when_collector_errors() {
+  let reporter = yield getJustReporter("shutdown_when_collector_errors", SERVER_URI, true);
+
+  reporter.onInitializeCollectorFinished = function () {
+    print("Throwing fake error.");
+    throw new Error("Fake error during collector initialization.");
+  };
+
+  // This will hang if shutdown logic is busted.
+  reporter._waitForShutdown();
+  do_check_eq(reporter.collectorShutdownCount, 1);
+  do_check_eq(reporter.storageCloseCount, 1);
+});
+
 add_task(function test_register_providers_from_category_manager() {
   const category = "healthreporter-js-modules";
 
   let cm = Cc["@mozilla.org/categorymanager;1"]
              .getService(Ci.nsICategoryManager);
   cm.addCategoryEntry(category, "DummyProvider",
                       "resource://testing-common/services/metrics/mocks.jsm",
                       false, true);