Bug 684783 - Fix intermittent test_errorhandler.js. r=philikon
authorRichard Newman <rnewman@mozilla.com>
Tue, 06 Sep 2011 13:09:29 -0700
changeset 76746 df706d14c53d65aa37aabb70533f2b3f95a2c9b1
parent 76745 29bba7fb6ddc653b7ad50d1a7112b59c22243613
child 76747 607edee2e848fd500712187bac05241a8cc34880
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
@@ -1236,80 +1236,83 @@ add_test(function test_crypto_keys_login
 });
 
 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);
 });