Bug 629664: Sync: only register engine once in checkServerError test, amongst other things. r=philiKON
authorRichard Newman <rnewman@mozilla.com>
Wed, 09 Feb 2011 22:43:21 -0800
changeset 62333 6c2446bf14ee9fb1aaa5eb40903fedc3cd242c73
parent 62332 fd42b5a411aa106e74039bf1b33d4f9c24ae323a
child 62334 36ba0ce7bdb9d6e6f8209a9026cad74e7e8b4ba5
child 62335 74db19f6be874cd0b2e7e44af98a70f44a1ff61d
push id1
push userroot
push dateTue, 10 Dec 2013 15:46:25 +0000
reviewersphiliKON
bugs629664
Bug 629664: Sync: only register engine once in checkServerError test, amongst other things. r=philiKON
services/sync/tests/unit/test_service_sync_checkServerError.js
--- a/services/sync/tests/unit/test_service_sync_checkServerError.js
+++ b/services/sync/tests/unit/test_service_sync_checkServerError.js
@@ -20,22 +20,27 @@ CatapultEngine.prototype = {
   }
 };
 
 function sync_httpd_setup() {
   let collectionsHelper = track_collections_helper();
   let upd = collectionsHelper.with_updated_collection;
   let collections = collectionsHelper.collections;
 
+  let catapultEngine = Engines.get("catapult");
+  let engines        = {catapult: {version: catapultEngine.version,
+                                   syncID:  catapultEngine.syncID}}
+
   // Track these using the collections helper, which keeps modified times
   // up-to-date.
+  let clientsColl = new ServerCollection({}, true);
   let keysWBO     = new ServerWBO("keys");
-  let clientsColl = new ServerCollection({}, true);
   let globalWBO   = new ServerWBO("global", {storageVersion: STORAGE_VERSION,
-                                             syncID: Utils.makeGUID()});
+                                             syncID: Utils.makeGUID(),
+                                             engines: engines});
 
   let handlers = {
     "/1.0/johndoe/info/collections":    collectionsHelper.handler,
     "/1.0/johndoe/storage/meta/global": upd("meta",    globalWBO.handler()),
     "/1.0/johndoe/storage/clients":     upd("clients", clientsColl.handler()),
     "/1.0/johndoe/storage/crypto/keys": upd("crypto",  keysWBO.handler())
   }
   return httpd_setup(handlers);
@@ -56,45 +61,42 @@ function generateAndUploadKeys() {
   return serverKeys.upload("http://localhost:8080/1.0/johndoe/storage/crypto/keys").success;
 }
 
 function test_backoff500(next) {
   _("Test: HTTP 500 sets backoff status.");
   let server = sync_httpd_setup();
   setUp();
 
-  Engines.register(CatapultEngine);
   let engine = Engines.get("catapult");
   engine.enabled = true;
   engine.exception = {status: 500};
 
   try {
     do_check_false(Status.enforceBackoff);
 
     // Forcibly create and upload keys here -- otherwise we don't get to the 500!
     do_check_true(generateAndUploadKeys());
 
     Service.login();
     Service.sync();
     do_check_true(Status.enforceBackoff);
   } finally {
-    Engines.unregister("catapult");
     Status.resetBackoff();
     Service.startOver();
   }
   server.stop(next);
 }
 
 function test_backoff503(next) {
   _("Test: HTTP 503 with Retry-After header leads to backoff notification and sets backoff status.");
   let server = sync_httpd_setup();
   setUp();
 
   const BACKOFF = 42;
-  Engines.register(CatapultEngine);
   let engine = Engines.get("catapult");
   engine.enabled = true;
   engine.exception = {status: 503,
                       headers: {"retry-after": BACKOFF}};
 
   let backoffInterval;
   Svc.Obs.add("weave:service:backoff:interval", function (subject) {
     backoffInterval = subject;
@@ -106,45 +108,42 @@ function test_backoff503(next) {
     do_check_true(generateAndUploadKeys());
 
     Service.login();
     Service.sync();
 
     do_check_true(Status.enforceBackoff);
     do_check_eq(backoffInterval, BACKOFF);
   } finally {
-    Engines.unregister("catapult");
     Status.resetBackoff();
     Service.startOver();
   }
   server.stop(next);
 }
 
 function test_overQuota(next) {
   _("Test: HTTP 400 with body error code 14 means over quota.");
   let server = sync_httpd_setup();
   setUp();
 
-  Engines.register(CatapultEngine);
   let engine = Engines.get("catapult");
   engine.enabled = true;
   engine.exception = {status: 400,
                       toString: function() "14"};
 
   try {
     do_check_eq(Status.sync, SYNC_SUCCEEDED);
 
     do_check_true(generateAndUploadKeys());
 
     Service.login();
     Service.sync();
 
     do_check_eq(Status.sync, OVER_QUOTA);
   } finally {
-    Engines.unregister("catapult");
     Status.resetSync();
     Service.startOver();
   }
   server.stop(next);
 }
 
 function test_service_networkError(next) {
   _("Test: Connection refused error from Service.sync() leads to the right status code.");
@@ -191,16 +190,20 @@ function test_service_offline(next) {
 }
 
 function test_service_reset_ignorableErrorCount(next) {
   _("Test: Successful sync resets the ignorable error count.");
   let server = sync_httpd_setup();
   setUp();
   Service._ignorableErrorCount = 10;
 
+  // Disable the engine so that sync completes.
+  let engine = Engines.get("catapult");
+  engine.enabled = false;
+
   try {
     do_check_eq(Status.sync, SYNC_SUCCEEDED);
 
     do_check_true(generateAndUploadKeys());
 
     Service.login();
     Service.sync();
 
@@ -214,75 +217,75 @@ function test_service_reset_ignorableErr
 }
 
 function test_engine_networkError(next) {
   _("Test: Network related exceptions from engine.sync() lead to the right status code.");
   let server = sync_httpd_setup();
   setUp();
   Service._ignorableErrorCount = 0;
 
-  Engines.register(CatapultEngine);
   let engine = Engines.get("catapult");
   engine.enabled = true;
   engine.exception = Components.Exception("NS_ERROR_UNKNOWN_HOST",
                                           Cr.NS_ERROR_UNKNOWN_HOST);
 
   try {
     do_check_eq(Status.sync, SYNC_SUCCEEDED);
 
     do_check_true(generateAndUploadKeys());
 
     Service.login();
     Service.sync();
 
     do_check_eq(Status.sync, LOGIN_FAILED_NETWORK_ERROR);
     do_check_eq(Service._ignorableErrorCount, 1);
   } finally {
-    Engines.unregister("catapult");
     Status.resetSync();
     Service.startOver();
   }
   server.stop(next);
 }
 
 // Slightly misplaced test as it doesn't actually test checkServerError,
 // but the observer for "weave:engine:sync:apply-failed".
 function test_engine_applyFailed(next) {
   let server = sync_httpd_setup();
   setUp();
 
-  Engines.register(CatapultEngine);
   let engine = Engines.get("catapult");
   engine.enabled = true;
+  delete engine.exception;
   engine.sync = function sync() {
     Svc.Obs.notify("weave:engine:sync:apply-failed", {}, "steam");
   };
 
   try {
     do_check_eq(Status.engines["steam"], undefined);
 
     do_check_true(generateAndUploadKeys());
 
     Service.login();
     Service.sync();
 
     do_check_eq(Status.engines["steam"], ENGINE_APPLY_FAIL);
   } finally {
-    Engines.unregister("catapult");
     Status.resetSync();
     Service.startOver();
   }
   server.stop(next);
 }
 
 function run_test() {
   if (DISABLE_TESTS_BUG_604565)
     return;
 
   do_test_pending();
+
+  // Register engine once.
+  Engines.register(CatapultEngine);
   asyncChainTests(test_backoff500,
                   test_backoff503,
                   test_overQuota,
                   test_service_networkError,
                   test_service_offline,
                   test_service_reset_ignorableErrorCount,
                   test_engine_networkError,
                   test_engine_applyFailed,