зеркало из https://github.com/mozilla/gecko-dev.git
Bug 684798 - Part 3: Catch server errors when wiping/disabling engines. r=rnewman
This commit is contained in:
Родитель
d04acc15c4
Коммит
315945275a
|
@ -724,7 +724,7 @@ SyncEngine.prototype = {
|
||||||
// Delete any existing data and reupload on bad version or missing meta.
|
// Delete any existing data and reupload on bad version or missing meta.
|
||||||
// No crypto component here...? We could regenerate per-collection keys...
|
// No crypto component here...? We could regenerate per-collection keys...
|
||||||
if (needsWipe) {
|
if (needsWipe) {
|
||||||
this.wipeServer(true);
|
this.wipeServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save objects that need to be uploaded in this._modified. We also save
|
// Save objects that need to be uploaded in this._modified. We also save
|
||||||
|
@ -1248,7 +1248,10 @@ SyncEngine.prototype = {
|
||||||
},
|
},
|
||||||
|
|
||||||
wipeServer: function wipeServer() {
|
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();
|
this._resetClient();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1372,7 +1372,14 @@ WeaveSvc.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update engines because it might change what we sync.
|
// 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 {
|
try {
|
||||||
for each (let engine in Engines.getEnabled()) {
|
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/util.js");
|
||||||
Cu.import("resource://services-sync/constants.js");
|
Cu.import("resource://services-sync/constants.js");
|
||||||
Cu.import("resource://services-sync/record.js");
|
Cu.import("resource://services-sync/record.js");
|
||||||
|
Cu.import("resource://services-sync/status.js");
|
||||||
|
|
||||||
Svc.DefaultPrefs.set("registerEngines", "");
|
Svc.DefaultPrefs.set("registerEngines", "");
|
||||||
Cu.import("resource://services-sync/service.js");
|
Cu.import("resource://services-sync/service.js");
|
||||||
|
Cu.import("resource://services-sync/policies.js");
|
||||||
|
|
||||||
initTestLogging();
|
initTestLogging();
|
||||||
|
|
||||||
|
@ -84,6 +86,9 @@ const PAYLOAD = 42;
|
||||||
|
|
||||||
function run_test() {
|
function run_test() {
|
||||||
initTestLogging("Trace");
|
initTestLogging("Trace");
|
||||||
|
Log4Moz.repository.getLogger("Sync.Service").level = Log4Moz.Level.Trace;
|
||||||
|
Log4Moz.repository.getLogger("Sync.ErrorHandler").level = Log4Moz.Level.Trace;
|
||||||
|
|
||||||
run_next_test();
|
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() {
|
add_test(function test_enabledRemotely() {
|
||||||
_("Test: Engine is disabled locally and enabled on a remote client");
|
_("Test: Engine is disabled locally and enabled on a remote client");
|
||||||
Service.syncID = "abcdefghij";
|
Service.syncID = "abcdefghij";
|
||||||
|
|
Загрузка…
Ссылка в новой задаче