зеркало из https://github.com/mozilla/pjs.git
Bug 684798 - Part 3: Catch server errors when wiping/disabling engines. r=rnewman
This commit is contained in:
Родитель
f9ceb7c5f0
Коммит
9b101bf1d1
|
@ -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();
|
||||
},
|
||||
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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";
|
||||
|
|
Загрузка…
Ссылка в новой задаче