From 9b101bf1d1da308ca4b56e2493ab97c5fd94a3f7 Mon Sep 17 00:00:00 2001 From: Philipp von Weitershausen Date: Wed, 12 Oct 2011 13:55:19 -0700 Subject: [PATCH] Bug 684798 - Part 3: Catch server errors when wiping/disabling engines. r=rnewman --- services/sync/modules/engines.js | 7 ++- services/sync/modules/service.js | 9 +++- .../test_service_sync_updateEnabledEngines.js | 49 +++++++++++++++++++ 3 files changed, 62 insertions(+), 3 deletions(-) diff --git a/services/sync/modules/engines.js b/services/sync/modules/engines.js index 90c6f894cee..09f7fdd7c34 100644 --- a/services/sync/modules/engines.js +++ b/services/sync/modules/engines.js @@ -724,7 +724,7 @@ SyncEngine.prototype = { // Delete any existing data and reupload on bad version or missing meta. // No crypto component here...? We could regenerate per-collection keys... if (needsWipe) { - this.wipeServer(true); + this.wipeServer(); } // Save objects that need to be uploaded in this._modified. We also save @@ -1248,7 +1248,10 @@ SyncEngine.prototype = { }, wipeServer: function wipeServer() { - new Resource(this.engineURL).delete(); + let response = new Resource(this.engineURL).delete(); + if (response.status != 200 && response.status != 404) { + throw response; + } this._resetClient(); }, diff --git a/services/sync/modules/service.js b/services/sync/modules/service.js index 397428e3f50..66ed837f125 100644 --- a/services/sync/modules/service.js +++ b/services/sync/modules/service.js @@ -1372,7 +1372,14 @@ WeaveSvc.prototype = { } // Update engines because it might change what we sync. - this._updateEnabledEngines(); + try { + this._updateEnabledEngines(); + } catch (ex) { + this._log.debug("Updating enabled engines failed: " + + Utils.exceptionStr(ex)); + ErrorHandler.checkServerError(ex); + throw ex; + } try { for each (let engine in Engines.getEnabled()) { diff --git a/services/sync/tests/unit/test_service_sync_updateEnabledEngines.js b/services/sync/tests/unit/test_service_sync_updateEnabledEngines.js index b4202b7c7fe..598633b3c32 100644 --- a/services/sync/tests/unit/test_service_sync_updateEnabledEngines.js +++ b/services/sync/tests/unit/test_service_sync_updateEnabledEngines.js @@ -3,9 +3,11 @@ Cu.import("resource://services-sync/engines/clients.js"); Cu.import("resource://services-sync/util.js"); Cu.import("resource://services-sync/constants.js"); Cu.import("resource://services-sync/record.js"); +Cu.import("resource://services-sync/status.js"); Svc.DefaultPrefs.set("registerEngines", ""); Cu.import("resource://services-sync/service.js"); +Cu.import("resource://services-sync/policies.js"); initTestLogging(); @@ -84,6 +86,9 @@ const PAYLOAD = 42; function run_test() { initTestLogging("Trace"); + Log4Moz.repository.getLogger("Sync.Service").level = Log4Moz.Level.Trace; + Log4Moz.repository.getLogger("Sync.ErrorHandler").level = Log4Moz.Level.Trace; + run_next_test(); } @@ -186,6 +191,50 @@ add_test(function test_disabledLocally() { } }); +add_test(function test_disabledLocally_wipe503() { + _("Test: Engine is enabled on remote clients and disabled locally"); + Service.syncID = "abcdefghij"; + let engine = Engines.get("steam"); + let metaWBO = new ServerWBO("global", { + syncID: Service.syncID, + storageVersion: STORAGE_VERSION, + engines: {steam: {syncID: engine.syncID, + version: engine.version}} + }); + let steamCollection = new ServerWBO("steam", PAYLOAD); + + function service_unavailable(request, response) { + let body = "Service Unavailable"; + response.setStatusLine(request.httpVersion, 503, "Service Unavailable"); + response.setHeader("Retry-After", "23"); + response.bodyOutputStream.write(body, body.length); + } + + let server = sync_httpd_setup({ + "/1.1/johndoe/storage/meta/global": metaWBO.handler(), + "/1.1/johndoe/storage/steam": service_unavailable + }); + setUp(); + + _("Disable engine locally."); + Service._ignorePrefObserver = true; + engine.enabled = true; + Service._ignorePrefObserver = false; + engine.enabled = false; + + Svc.Obs.add("weave:ui:sync:error", function onSyncError() { + Svc.Obs.remove("weave:ui:sync:error", onSyncError); + + do_check_eq(Status.sync, SERVER_MAINTENANCE); + + Service.startOver(); + server.stop(run_next_test); + }); + + _("Sync."); + ErrorHandler.syncAndReportErrors(); +}); + add_test(function test_enabledRemotely() { _("Test: Engine is disabled locally and enabled on a remote client"); Service.syncID = "abcdefghij";