Bug 684783 - Fix intermittent test_errorhandler.js. r=philikon
authorRichard Newman <rnewman@mozilla.com>
Tue, 06 Sep 2011 08:26:35 -0700
changeset 76602 2dc945c5c66e3a39e4596e7cbbe10fe26593f777
parent 76601 db2ec1f8df574db9f67b3c7cddbe609545cf7ad2
child 76603 f921f632208e2a7e9eba943c6dce96a8b6a33b77
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersphilikon
bugs684783
milestone9.0a1
Bug 684783 - Fix intermittent test_errorhandler.js. r=philikon
services/sync/tests/unit/test_errorhandler.js
--- a/services/sync/tests/unit/test_errorhandler.js
+++ b/services/sync/tests/unit/test_errorhandler.js
@@ -762,80 +762,83 @@ add_test(function test_syncAndReportErro
 });
 
 add_test(function test_sync_engine_generic_fail() {
   let server = sync_httpd_setup();
 
   let engine = Engines.get("catapult");
   engine.enabled = true;
   engine.sync = function sync() {
-    Svc.Obs.notify("weave:engine:sync:error", "", "steam");
+    Svc.Obs.notify("weave:engine:sync:error", "", "catapult");
   };
 
   let log = Log4Moz.repository.getLogger("Sync.ErrorHandler");
   Svc.Prefs.set("log.appender.file.logOnError", true);
 
   Svc.Obs.add("weave:service:reset-file-log", function onResetFileLog() {
     Svc.Obs.remove("weave:service:reset-file-log", onResetFileLog);
 
+    // Put these checks here, not after sync(), so that we aren't racing the
+    // log handler... which resets everything just a few lines below!
+    _("Status.engines: " + JSON.stringify(Status.engines));
+    do_check_eq(Status.engines["catapult"], ENGINE_UNKNOWN_FAIL);
+    do_check_eq(Status.service, SYNC_FAILED_PARTIAL);
+
     // Test Error log was written on SYNC_FAILED_PARTIAL.
     let entries = logsdir.directoryEntries;
     do_check_true(entries.hasMoreElements());
     let logfile = entries.getNext().QueryInterface(Ci.nsILocalFile);
     do_check_eq(logfile.leafName.slice(0, LOG_PREFIX_ERROR.length),
                 LOG_PREFIX_ERROR);
 
     Status.resetSync();
     Service.startOver();
 
     server.stop(run_next_test);
   });
 
-  do_check_eq(Status.engines["steam"], undefined);
+  do_check_eq(Status.engines["catapult"], undefined);
 
   do_check_true(setUp());
 
   Service.sync();
-
-  do_check_eq(Status.engines["steam"], ENGINE_UNKNOWN_FAIL);
-  do_check_eq(Status.service, SYNC_FAILED_PARTIAL);
 });
 
 // This test should be the last one since it monkeypatches the engine object
 // and we should only have one engine object throughout the file (bug 629664).
 add_test(function test_engine_applyFailed() {
   let server = sync_httpd_setup();
 
   let engine = Engines.get("catapult");
   engine.enabled = true;
   delete engine.exception;
   engine.sync = function sync() {
-    Svc.Obs.notify("weave:engine:sync:applied", {newFailed:1}, "steam");
+    Svc.Obs.notify("weave:engine:sync:applied", {newFailed:1}, "catapult");
   };
 
   let log = Log4Moz.repository.getLogger("Sync.ErrorHandler");
   Svc.Prefs.set("log.appender.file.logOnError", true);
 
   Svc.Obs.add("weave:service:reset-file-log", function onResetFileLog() {
     Svc.Obs.remove("weave:service:reset-file-log", onResetFileLog);
 
+    do_check_eq(Status.engines["catapult"], ENGINE_APPLY_FAIL);
+    do_check_eq(Status.service, SYNC_FAILED_PARTIAL);
+
     // Test Error log was written on SYNC_FAILED_PARTIAL.
     let entries = logsdir.directoryEntries;
     do_check_true(entries.hasMoreElements());
     let logfile = entries.getNext().QueryInterface(Ci.nsILocalFile);
     do_check_eq(logfile.leafName.slice(0, LOG_PREFIX_ERROR.length),
                 LOG_PREFIX_ERROR);
 
     Status.resetSync();
     Service.startOver();
 
     server.stop(run_next_test);
   });
 
-  do_check_eq(Status.engines["steam"], undefined);
+  do_check_eq(Status.engines["catapult"], undefined);
 
   do_check_true(setUp());
 
   Service.sync();
-
-  do_check_eq(Status.engines["steam"], ENGINE_APPLY_FAIL);
-  do_check_eq(Status.service, SYNC_FAILED_PARTIAL);
 });