mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 949695 tests followup - convert more tests to run with both identity managers.
This commit is contained in:
parent
789370bf6f
commit
152f80143a
@ -6,7 +6,7 @@ Cu.import("resource://services-sync/service.js");
|
||||
Cu.import("resource://services-sync/util.js");
|
||||
Cu.import("resource://testing-common/services/sync/utils.js");
|
||||
|
||||
add_test(function test_missing_crypto_collection() {
|
||||
add_identity_test(this, function test_missing_crypto_collection() {
|
||||
let johnHelper = track_collections_helper();
|
||||
let johnU = johnHelper.with_updated_collection;
|
||||
let johnColls = johnHelper.collections;
|
||||
@ -24,7 +24,7 @@ add_test(function test_missing_crypto_collection() {
|
||||
};
|
||||
}
|
||||
|
||||
setBasicCredentials("johndoe", "ilovejane", "a-aaaaa-aaaaa-aaaaa-aaaaa-aaaaa");
|
||||
yield configureIdentity({username: "johndoe"});
|
||||
|
||||
let handlers = {
|
||||
"/1.1/johndoe/info/collections": maybe_empty(johnHelper.handler),
|
||||
@ -70,7 +70,9 @@ add_test(function test_missing_crypto_collection() {
|
||||
|
||||
} finally {
|
||||
Svc.Prefs.resetBranch("");
|
||||
server.stop(run_next_test);
|
||||
let deferred = Promise.defer();
|
||||
server.stop(deferred.resolve);
|
||||
yield deferred.promise;
|
||||
}
|
||||
});
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -44,7 +44,7 @@ function sync_httpd_setup(infoHandler) {
|
||||
}
|
||||
|
||||
function setUp(server) {
|
||||
setBasicCredentials("johndoe", "ilovejane", "aabcdeabcdeabcdeabcdeabcde");
|
||||
yield configureIdentity({username: "johndoe"});
|
||||
Service.serverURL = server.baseURI + "/";
|
||||
Service.clusterURL = server.baseURI + "/";
|
||||
new FakeCryptoService();
|
||||
@ -66,39 +66,42 @@ function do_check_hard_eol(eh, start) {
|
||||
do_check_true(Status.eol);
|
||||
}
|
||||
|
||||
add_test(function test_200_hard() {
|
||||
add_identity_test(this, function test_200_hard() {
|
||||
let eh = Service.errorHandler;
|
||||
let start = Date.now();
|
||||
let server = sync_httpd_setup(handler200("hard-eol"));
|
||||
setUp(server);
|
||||
yield setUp(server);
|
||||
|
||||
let deferred = Promise.defer();
|
||||
let obs = function (subject, topic, data) {
|
||||
Svc.Obs.remove("weave:eol", obs);
|
||||
do_check_eq("hard-eol", subject.code);
|
||||
do_check_hard_eol(eh, start);
|
||||
do_check_eq(Service.scheduler.eolInterval, Service.scheduler.syncInterval);
|
||||
eh.clearServerAlerts();
|
||||
server.stop(run_next_test);
|
||||
server.stop(deferred.resolve);
|
||||
};
|
||||
|
||||
Svc.Obs.add("weave:eol", obs);
|
||||
Service._fetchInfo();
|
||||
Service.scheduler.adjustSyncInterval(); // As if we failed or succeeded in syncing.
|
||||
yield deferred.promise;
|
||||
});
|
||||
|
||||
add_test(function test_513_hard() {
|
||||
add_identity_test(this, function test_513_hard() {
|
||||
let eh = Service.errorHandler;
|
||||
let start = Date.now();
|
||||
let server = sync_httpd_setup(handler513);
|
||||
setUp(server);
|
||||
yield setUp(server);
|
||||
|
||||
let deferred = Promise.defer();
|
||||
let obs = function (subject, topic, data) {
|
||||
Svc.Obs.remove("weave:eol", obs);
|
||||
do_check_eq("hard-eol", subject.code);
|
||||
do_check_hard_eol(eh, start);
|
||||
do_check_eq(Service.scheduler.eolInterval, Service.scheduler.syncInterval);
|
||||
eh.clearServerAlerts();
|
||||
server.stop(run_next_test);
|
||||
server.stop(deferred.resolve);
|
||||
};
|
||||
|
||||
Svc.Obs.add("weave:eol", obs);
|
||||
@ -108,24 +111,27 @@ add_test(function test_513_hard() {
|
||||
} catch (ex) {
|
||||
// Because fetchInfo will fail on a 513.
|
||||
}
|
||||
yield deferred.promise;
|
||||
});
|
||||
|
||||
add_test(function test_200_soft() {
|
||||
add_identity_test(this, function test_200_soft() {
|
||||
let eh = Service.errorHandler;
|
||||
let start = Date.now();
|
||||
let server = sync_httpd_setup(handler200("soft-eol"));
|
||||
setUp(server);
|
||||
yield setUp(server);
|
||||
|
||||
let deferred = Promise.defer();
|
||||
let obs = function (subject, topic, data) {
|
||||
Svc.Obs.remove("weave:eol", obs);
|
||||
do_check_eq("soft-eol", subject.code);
|
||||
do_check_soft_eol(eh, start);
|
||||
do_check_eq(Service.scheduler.singleDeviceInterval, Service.scheduler.syncInterval);
|
||||
eh.clearServerAlerts();
|
||||
server.stop(run_next_test);
|
||||
server.stop(deferred.resolve);
|
||||
};
|
||||
|
||||
Svc.Obs.add("weave:eol", obs);
|
||||
Service._fetchInfo();
|
||||
Service.scheduler.adjustSyncInterval(); // As if we failed or succeeded in syncing.
|
||||
yield deferred.promise;
|
||||
});
|
||||
|
@ -16,6 +16,12 @@ initTestLogging("Trace");
|
||||
let engineManager = Service.engineManager;
|
||||
engineManager.clear();
|
||||
|
||||
function promiseStopServer(server) {
|
||||
let deferred = Promise.defer();
|
||||
server.stop(deferred.resolve);
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function CatapultEngine() {
|
||||
SyncEngine.call(this, "Catapult", Service);
|
||||
}
|
||||
@ -54,7 +60,7 @@ function sync_httpd_setup() {
|
||||
}
|
||||
|
||||
function setUp(server) {
|
||||
setBasicCredentials("johndoe", "ilovejane", "aabcdeabcdeabcdeabcdeabcde");
|
||||
yield configureIdentity({username: "johndoe"});
|
||||
Service.serverURL = server.baseURI + "/";
|
||||
Service.clusterURL = server.baseURI + "/";
|
||||
new FakeCryptoService();
|
||||
@ -69,10 +75,10 @@ function generateAndUploadKeys(server) {
|
||||
}
|
||||
|
||||
|
||||
add_test(function test_backoff500() {
|
||||
add_identity_test(this, function test_backoff500() {
|
||||
_("Test: HTTP 500 sets backoff status.");
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
yield setUp(server);
|
||||
|
||||
let engine = engineManager.get("catapult");
|
||||
engine.enabled = true;
|
||||
@ -93,13 +99,13 @@ add_test(function test_backoff500() {
|
||||
Status.resetBackoff();
|
||||
Service.startOver();
|
||||
}
|
||||
server.stop(run_next_test);
|
||||
yield promiseStopServer(server);
|
||||
});
|
||||
|
||||
add_test(function test_backoff503() {
|
||||
add_identity_test(this, function test_backoff503() {
|
||||
_("Test: HTTP 503 with Retry-After header leads to backoff notification and sets backoff status.");
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
yield setUp(server);
|
||||
|
||||
const BACKOFF = 42;
|
||||
let engine = engineManager.get("catapult");
|
||||
@ -129,13 +135,13 @@ add_test(function test_backoff503() {
|
||||
Status.resetSync();
|
||||
Service.startOver();
|
||||
}
|
||||
server.stop(run_next_test);
|
||||
yield promiseStopServer(server);
|
||||
});
|
||||
|
||||
add_test(function test_overQuota() {
|
||||
add_identity_test(this, function test_overQuota() {
|
||||
_("Test: HTTP 400 with body error code 14 means over quota.");
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
yield setUp(server);
|
||||
|
||||
let engine = engineManager.get("catapult");
|
||||
engine.enabled = true;
|
||||
@ -156,13 +162,14 @@ add_test(function test_overQuota() {
|
||||
Status.resetSync();
|
||||
Service.startOver();
|
||||
}
|
||||
server.stop(run_next_test);
|
||||
yield promiseStopServer(server);
|
||||
});
|
||||
|
||||
add_test(function test_service_networkError() {
|
||||
add_identity_test(this, function test_service_networkError() {
|
||||
_("Test: Connection refused error from Service.sync() leads to the right status code.");
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
yield setUp(server);
|
||||
let deferred = Promise.defer();
|
||||
server.stop(() => {
|
||||
// Provoke connection refused.
|
||||
Service.clusterURL = "http://localhost:12345/";
|
||||
@ -179,14 +186,16 @@ add_test(function test_service_networkError() {
|
||||
Status.resetSync();
|
||||
Service.startOver();
|
||||
}
|
||||
run_next_test();
|
||||
deferred.resolve();
|
||||
});
|
||||
yield deferred.promise;
|
||||
});
|
||||
|
||||
add_test(function test_service_offline() {
|
||||
add_identity_test(this, function test_service_offline() {
|
||||
_("Test: Wanting to sync in offline mode leads to the right status code but does not increment the ignorable error count.");
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
yield setUp(server);
|
||||
let deferred = Promise.defer();
|
||||
server.stop(() => {
|
||||
Services.io.offline = true;
|
||||
|
||||
@ -203,14 +212,15 @@ add_test(function test_service_offline() {
|
||||
Service.startOver();
|
||||
}
|
||||
Services.io.offline = false;
|
||||
run_next_test();
|
||||
deferred.resolve();
|
||||
});
|
||||
yield deferred.promise;
|
||||
});
|
||||
|
||||
add_test(function test_engine_networkError() {
|
||||
add_identity_test(this, function test_engine_networkError() {
|
||||
_("Test: Network related exceptions from engine.sync() lead to the right status code.");
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
yield setUp(server);
|
||||
|
||||
let engine = engineManager.get("catapult");
|
||||
engine.enabled = true;
|
||||
@ -231,12 +241,12 @@ add_test(function test_engine_networkError() {
|
||||
Status.resetSync();
|
||||
Service.startOver();
|
||||
}
|
||||
server.stop(run_next_test);
|
||||
yield promiseStopServer(server);
|
||||
});
|
||||
|
||||
add_test(function test_resource_timeout() {
|
||||
add_identity_test(this, function test_resource_timeout() {
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
yield setUp(server);
|
||||
|
||||
let engine = engineManager.get("catapult");
|
||||
engine.enabled = true;
|
||||
@ -258,7 +268,7 @@ add_test(function test_resource_timeout() {
|
||||
Status.resetSync();
|
||||
Service.startOver();
|
||||
}
|
||||
server.stop(run_next_test);
|
||||
yield promiseStopServer(server);
|
||||
});
|
||||
|
||||
function run_test() {
|
||||
|
@ -13,6 +13,12 @@ Cu.import("resource://services-sync/service.js");
|
||||
let scheduler = Service.scheduler;
|
||||
let clientsEngine = Service.clientsEngine;
|
||||
|
||||
function promiseStopServer(server) {
|
||||
let deferred = Promise.defer();
|
||||
server.stop(deferred.resolve);
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function sync_httpd_setup() {
|
||||
let global = new ServerWBO("global", {
|
||||
syncID: Service.syncID,
|
||||
@ -36,14 +42,13 @@ function sync_httpd_setup() {
|
||||
}
|
||||
|
||||
function setUp(server) {
|
||||
setBasicCredentials("johndoe", "ilovejane", "abcdeabcdeabcdeabcdeabcdea");
|
||||
yield configureIdentity({username: "johndoe"});
|
||||
Service.serverURL = server.baseURI + "/";
|
||||
Service.clusterURL = server.baseURI + "/";
|
||||
|
||||
generateNewKeys(Service.collectionKeys);
|
||||
let serverKeys = Service.collectionKeys.asWBO("crypto", "keys");
|
||||
serverKeys.encrypt(Service.identity.syncKeyBundle);
|
||||
return serverKeys.upload(Service.resource(Service.cryptoKeysURL));
|
||||
serverKeys.upload(Service.resource(Service.cryptoKeysURL));
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
@ -55,7 +60,7 @@ function run_test() {
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
add_test(function test_successful_sync_adjustSyncInterval() {
|
||||
add_identity_test(this, function test_successful_sync_adjustSyncInterval() {
|
||||
_("Test successful sync calling adjustSyncInterval");
|
||||
let syncSuccesses = 0;
|
||||
function onSyncFinish() {
|
||||
@ -65,7 +70,7 @@ add_test(function test_successful_sync_adjustSyncInterval() {
|
||||
Svc.Obs.add("weave:service:sync:finish", onSyncFinish);
|
||||
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
yield setUp(server);
|
||||
|
||||
// Confirm defaults
|
||||
do_check_false(scheduler.idle);
|
||||
@ -151,10 +156,10 @@ add_test(function test_successful_sync_adjustSyncInterval() {
|
||||
|
||||
Svc.Obs.remove("weave:service:sync:finish", onSyncFinish);
|
||||
Service.startOver();
|
||||
server.stop(run_next_test);
|
||||
yield promiseStopServer(server);
|
||||
});
|
||||
|
||||
add_test(function test_unsuccessful_sync_adjustSyncInterval() {
|
||||
add_identity_test(this, function test_unsuccessful_sync_adjustSyncInterval() {
|
||||
_("Test unsuccessful sync calling adjustSyncInterval");
|
||||
|
||||
let syncFailures = 0;
|
||||
@ -169,7 +174,7 @@ add_test(function test_unsuccessful_sync_adjustSyncInterval() {
|
||||
Svc.Prefs.set("firstSync", "notReady");
|
||||
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
yield setUp(server);
|
||||
|
||||
// Confirm defaults
|
||||
do_check_false(scheduler.idle);
|
||||
@ -256,12 +261,12 @@ add_test(function test_unsuccessful_sync_adjustSyncInterval() {
|
||||
|
||||
Service.startOver();
|
||||
Svc.Obs.remove("weave:service:sync:error", onSyncError);
|
||||
server.stop(run_next_test);
|
||||
yield promiseStopServer(server);
|
||||
});
|
||||
|
||||
add_test(function test_back_triggers_sync() {
|
||||
add_identity_test(this, function test_back_triggers_sync() {
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
yield setUp(server);
|
||||
|
||||
// Single device: no sync triggered.
|
||||
scheduler.idle = true;
|
||||
@ -272,6 +277,7 @@ add_test(function test_back_triggers_sync() {
|
||||
clientsEngine._store.create({id: "foo", cleartext: "bar"});
|
||||
scheduler.updateClientMode();
|
||||
|
||||
let deferred = Promise.defer();
|
||||
Svc.Obs.add("weave:service:sync:finish", function onSyncFinish() {
|
||||
Svc.Obs.remove("weave:service:sync:finish", onSyncFinish);
|
||||
|
||||
@ -281,17 +287,18 @@ add_test(function test_back_triggers_sync() {
|
||||
clientsEngine.resetClient();
|
||||
|
||||
Service.startOver();
|
||||
server.stop(run_next_test);
|
||||
server.stop(deferred.resolve);
|
||||
});
|
||||
|
||||
scheduler.idle = true;
|
||||
scheduler.observe(null, "back", Svc.Prefs.get("scheduler.idleTime"));
|
||||
do_check_false(scheduler.idle);
|
||||
yield deferred.promise;
|
||||
});
|
||||
|
||||
add_test(function test_adjust_interval_on_sync_error() {
|
||||
add_identity_test(this, function test_adjust_interval_on_sync_error() {
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
yield setUp(server);
|
||||
|
||||
let syncFailures = 0;
|
||||
function onSyncError() {
|
||||
@ -317,17 +324,17 @@ add_test(function test_adjust_interval_on_sync_error() {
|
||||
|
||||
Svc.Obs.remove("weave:service:sync:error", onSyncError);
|
||||
Service.startOver();
|
||||
server.stop(run_next_test);
|
||||
yield promiseStopServer(server);
|
||||
});
|
||||
|
||||
add_test(function test_bug671378_scenario() {
|
||||
add_identity_test(this, function test_bug671378_scenario() {
|
||||
// Test scenario similar to bug 671378. This bug appeared when a score
|
||||
// update occurred that wasn't large enough to trigger a sync so
|
||||
// scheduleNextSync() was called without a time interval parameter,
|
||||
// setting nextSync to a non-zero value and preventing the timer from
|
||||
// being adjusted in the next call to scheduleNextSync().
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
yield setUp(server);
|
||||
|
||||
let syncSuccesses = 0;
|
||||
function onSyncFinish() {
|
||||
@ -343,6 +350,7 @@ add_test(function test_bug671378_scenario() {
|
||||
do_check_eq(scheduler.syncInterval, scheduler.singleDeviceInterval);
|
||||
do_check_eq(scheduler.syncTimer.delay, scheduler.singleDeviceInterval);
|
||||
|
||||
let deferred = Promise.defer();
|
||||
// Wrap scheduleNextSync so we are notified when it is finished.
|
||||
scheduler._scheduleNextSync = scheduler.scheduleNextSync;
|
||||
scheduler.scheduleNextSync = function() {
|
||||
@ -358,7 +366,7 @@ add_test(function test_bug671378_scenario() {
|
||||
scheduler.scheduleNextSync = scheduler._scheduleNextSync;
|
||||
Svc.Obs.remove("weave:service:sync:finish", onSyncFinish);
|
||||
Service.startOver();
|
||||
server.stop(run_next_test);
|
||||
server.stop(deferred.resolve);
|
||||
}
|
||||
};
|
||||
|
||||
@ -381,6 +389,7 @@ add_test(function test_bug671378_scenario() {
|
||||
|
||||
clientsEngine._store.create({id: "foo", cleartext: "bar"});
|
||||
Service.sync();
|
||||
yield deferred.promise;
|
||||
});
|
||||
|
||||
add_test(function test_adjust_timer_larger_syncInterval() {
|
||||
|
@ -74,15 +74,17 @@ function installNodeHandler(server, next) {
|
||||
}
|
||||
|
||||
function prepareServer() {
|
||||
setBasicCredentials("johndoe", "ilovejane", "abcdeabcdeabcdeabcdeabcdea");
|
||||
|
||||
let server = new SyncServer();
|
||||
server.registerUser("johndoe");
|
||||
server.start();
|
||||
Service.serverURL = server.baseURI;
|
||||
Service.clusterURL = server.baseURI;
|
||||
do_check_eq(Service.userAPIURI, server.baseURI + "user/1.0/");
|
||||
return server;
|
||||
let deferred = Promise.defer();
|
||||
configureIdentity({username: "johndoe"}).then(() => {
|
||||
let server = new SyncServer();
|
||||
server.registerUser("johndoe");
|
||||
server.start();
|
||||
Service.serverURL = server.baseURI;
|
||||
Service.clusterURL = server.baseURI;
|
||||
do_check_eq(Service.userAPIURI, server.baseURI + "user/1.0/");
|
||||
deferred.resolve(server);
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function getReassigned() {
|
||||
@ -104,6 +106,7 @@ function getReassigned() {
|
||||
*/
|
||||
function syncAndExpectNodeReassignment(server, firstNotification, between,
|
||||
secondNotification, url) {
|
||||
let deferred = Promise.defer();
|
||||
function onwards() {
|
||||
let nodeFetched = false;
|
||||
function onFirstSync() {
|
||||
@ -138,7 +141,7 @@ function syncAndExpectNodeReassignment(server, firstNotification, between,
|
||||
_("Second sync nextTick.");
|
||||
do_check_true(nodeFetched);
|
||||
Service.startOver();
|
||||
server.stop(run_next_test);
|
||||
server.stop(deferred.resolve);
|
||||
});
|
||||
}
|
||||
|
||||
@ -152,11 +155,12 @@ function syncAndExpectNodeReassignment(server, firstNotification, between,
|
||||
do_check_eq(request.response.status, 401);
|
||||
Utils.nextTick(onwards);
|
||||
});
|
||||
yield deferred.promise;
|
||||
}
|
||||
|
||||
add_test(function test_momentary_401_engine() {
|
||||
add_identity_test(this, function test_momentary_401_engine() {
|
||||
_("Test a failure for engine URLs that's resolved by reassignment.");
|
||||
let server = prepareServer();
|
||||
let server = yield prepareServer();
|
||||
let john = server.user("johndoe");
|
||||
|
||||
_("Enabling the Rotary engine.");
|
||||
@ -198,17 +202,17 @@ add_test(function test_momentary_401_engine() {
|
||||
Svc.Obs.add("weave:service:login:start", onLoginStart);
|
||||
}
|
||||
|
||||
syncAndExpectNodeReassignment(server,
|
||||
"weave:service:sync:finish",
|
||||
between,
|
||||
"weave:service:sync:finish",
|
||||
Service.storageURL + "rotary");
|
||||
yield syncAndExpectNodeReassignment(server,
|
||||
"weave:service:sync:finish",
|
||||
between,
|
||||
"weave:service:sync:finish",
|
||||
Service.storageURL + "rotary");
|
||||
});
|
||||
|
||||
// This test ends up being a failing fetch *after we're already logged in*.
|
||||
add_test(function test_momentary_401_info_collections() {
|
||||
add_identity_test(this, function test_momentary_401_info_collections() {
|
||||
_("Test a failure for info/collections that's resolved by reassignment.");
|
||||
let server = prepareServer();
|
||||
let server = yield prepareServer();
|
||||
|
||||
_("First sync to prepare server contents.");
|
||||
Service.sync();
|
||||
@ -222,17 +226,17 @@ add_test(function test_momentary_401_info_collections() {
|
||||
server.toplevelHandlers.info = oldHandler;
|
||||
}
|
||||
|
||||
syncAndExpectNodeReassignment(server,
|
||||
"weave:service:sync:error",
|
||||
undo,
|
||||
"weave:service:sync:finish",
|
||||
Service.infoURL);
|
||||
yield syncAndExpectNodeReassignment(server,
|
||||
"weave:service:sync:error",
|
||||
undo,
|
||||
"weave:service:sync:finish",
|
||||
Service.infoURL);
|
||||
});
|
||||
|
||||
add_test(function test_momentary_401_storage() {
|
||||
add_identity_test(this, function test_momentary_401_storage() {
|
||||
_("Test a failure for any storage URL, not just engine parts. " +
|
||||
"Resolved by reassignment.");
|
||||
let server = prepareServer();
|
||||
let server = yield prepareServer();
|
||||
|
||||
// Return a 401 for all storage requests.
|
||||
let oldHandler = server.toplevelHandlers.storage;
|
||||
@ -243,18 +247,18 @@ add_test(function test_momentary_401_storage() {
|
||||
server.toplevelHandlers.storage = oldHandler;
|
||||
}
|
||||
|
||||
syncAndExpectNodeReassignment(server,
|
||||
"weave:service:login:error",
|
||||
undo,
|
||||
"weave:service:sync:finish",
|
||||
Service.storageURL + "meta/global");
|
||||
yield syncAndExpectNodeReassignment(server,
|
||||
"weave:service:login:error",
|
||||
undo,
|
||||
"weave:service:sync:finish",
|
||||
Service.storageURL + "meta/global");
|
||||
});
|
||||
|
||||
add_test(function test_loop_avoidance_storage() {
|
||||
add_identity_test(this, function test_loop_avoidance_storage() {
|
||||
_("Test that a repeated failure doesn't result in a sync loop " +
|
||||
"if node reassignment cannot resolve the failure.");
|
||||
|
||||
let server = prepareServer();
|
||||
let server = yield prepareServer();
|
||||
|
||||
// Return a 401 for all storage requests.
|
||||
let oldHandler = server.toplevelHandlers.storage;
|
||||
@ -265,6 +269,7 @@ add_test(function test_loop_avoidance_storage() {
|
||||
let thirdNotification = "weave:service:sync:finish";
|
||||
|
||||
let nodeFetched = false;
|
||||
let deferred = Promise.defer();
|
||||
|
||||
// Track the time. We want to make sure the duration between the first and
|
||||
// second sync is small, and then that the duration between second and third
|
||||
@ -338,7 +343,7 @@ add_test(function test_loop_avoidance_storage() {
|
||||
do_check_false(getReassigned());
|
||||
do_check_true(nodeFetched);
|
||||
Service.startOver();
|
||||
server.stop(run_next_test);
|
||||
server.stop(deferred.resolve);
|
||||
});
|
||||
}
|
||||
|
||||
@ -346,17 +351,19 @@ add_test(function test_loop_avoidance_storage() {
|
||||
|
||||
now = Date.now();
|
||||
Service.sync();
|
||||
yield deferred.promise;
|
||||
});
|
||||
|
||||
add_test(function test_loop_avoidance_engine() {
|
||||
add_identity_test(this, function test_loop_avoidance_engine() {
|
||||
_("Test that a repeated 401 in an engine doesn't result in a sync loop " +
|
||||
"if node reassignment cannot resolve the failure.");
|
||||
let server = prepareServer();
|
||||
let server = yield prepareServer();
|
||||
let john = server.user("johndoe");
|
||||
|
||||
_("Enabling the Rotary engine.");
|
||||
let engine = Service.engineManager.get("rotary");
|
||||
engine.enabled = true;
|
||||
let deferred = Promise.defer();
|
||||
|
||||
// We need the server to be correctly set up prior to experimenting. Do this
|
||||
// through a sync.
|
||||
@ -391,7 +398,7 @@ add_test(function test_loop_avoidance_engine() {
|
||||
function afterSuccessfulSync() {
|
||||
Svc.Obs.remove("weave:service:login:start", onLoginStart);
|
||||
Service.startOver();
|
||||
server.stop(run_next_test);
|
||||
server.stop(deferred.resolve);
|
||||
}
|
||||
|
||||
let firstNotification = "weave:service:sync:finish";
|
||||
@ -483,4 +490,5 @@ add_test(function test_loop_avoidance_engine() {
|
||||
|
||||
now = Date.now();
|
||||
Service.sync();
|
||||
yield deferred.promise;
|
||||
});
|
||||
|
@ -53,24 +53,30 @@ function sync_httpd_setup() {
|
||||
}
|
||||
|
||||
function setUp(server) {
|
||||
setBasicCredentials("johndoe", "ilovejane", "abcdeabcdeabcdeabcdeabcdea");
|
||||
Service.clusterURL = server.baseURI + "/";
|
||||
let deferred = Promise.defer();
|
||||
configureIdentity({username: "johndoe"}).then(() => {
|
||||
Service.clusterURL = server.baseURI + "/";
|
||||
|
||||
generateNewKeys(Service.collectionKeys);
|
||||
let serverKeys = Service.collectionKeys.asWBO("crypto", "keys");
|
||||
serverKeys.encrypt(Service.identity.syncKeyBundle);
|
||||
return serverKeys.upload(Service.resource(Service.cryptoKeysURL)).success;
|
||||
generateNewKeys(Service.collectionKeys);
|
||||
let serverKeys = Service.collectionKeys.asWBO("crypto", "keys");
|
||||
serverKeys.encrypt(Service.identity.syncKeyBundle);
|
||||
let result = serverKeys.upload(Service.resource(Service.cryptoKeysURL)).success;
|
||||
deferred.resolve(result);
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function cleanUpAndGo(server) {
|
||||
let deferred = Promise.defer();
|
||||
Utils.nextTick(function () {
|
||||
Service.startOver();
|
||||
if (server) {
|
||||
server.stop(run_next_test);
|
||||
server.stop(deferred.resolve);
|
||||
} else {
|
||||
run_next_test();
|
||||
deferred.resolve();
|
||||
}
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
@ -143,7 +149,7 @@ add_test(function test_prefAttributes() {
|
||||
run_next_test();
|
||||
});
|
||||
|
||||
add_test(function test_updateClientMode() {
|
||||
add_identity_test(this, function test_updateClientMode() {
|
||||
_("Test updateClientMode adjusts scheduling attributes based on # of clients appropriately");
|
||||
do_check_eq(scheduler.syncThreshold, SINGLE_USER_THRESHOLD);
|
||||
do_check_eq(scheduler.syncInterval, scheduler.singleDeviceInterval);
|
||||
@ -170,10 +176,10 @@ add_test(function test_updateClientMode() {
|
||||
do_check_false(scheduler.numClients > 1);
|
||||
do_check_false(scheduler.idle);
|
||||
|
||||
cleanUpAndGo();
|
||||
yield cleanUpAndGo();
|
||||
});
|
||||
|
||||
add_test(function test_masterpassword_locked_retry_interval() {
|
||||
add_identity_test(this, function test_masterpassword_locked_retry_interval() {
|
||||
_("Test Status.login = MASTER_PASSWORD_LOCKED results in reschedule at MASTER_PASSWORD interval");
|
||||
let loginFailed = false;
|
||||
Svc.Obs.add("weave:service:login:error", function onLoginError() {
|
||||
@ -196,7 +202,7 @@ add_test(function test_masterpassword_locked_retry_interval() {
|
||||
};
|
||||
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
yield setUp(server);
|
||||
|
||||
Service.sync();
|
||||
|
||||
@ -207,10 +213,10 @@ add_test(function test_masterpassword_locked_retry_interval() {
|
||||
Service.verifyLogin = oldVerifyLogin;
|
||||
SyncScheduler.prototype.scheduleAtInterval = oldScheduleAtInterval;
|
||||
|
||||
cleanUpAndGo(server);
|
||||
yield cleanUpAndGo(server);
|
||||
});
|
||||
|
||||
add_test(function test_calculateBackoff() {
|
||||
add_identity_test(this, function test_calculateBackoff() {
|
||||
do_check_eq(Status.backoffInterval, 0);
|
||||
|
||||
// Test no interval larger than the maximum backoff is used if
|
||||
@ -229,23 +235,25 @@ add_test(function test_calculateBackoff() {
|
||||
|
||||
do_check_eq(backoffInterval, MAXIMUM_BACKOFF_INTERVAL + 10);
|
||||
|
||||
cleanUpAndGo();
|
||||
yield cleanUpAndGo();
|
||||
});
|
||||
|
||||
add_test(function test_scheduleNextSync_nowOrPast() {
|
||||
add_identity_test(this, function test_scheduleNextSync_nowOrPast() {
|
||||
let deferred = Promise.defer();
|
||||
Svc.Obs.add("weave:service:sync:finish", function onSyncFinish() {
|
||||
Svc.Obs.remove("weave:service:sync:finish", onSyncFinish);
|
||||
cleanUpAndGo(server);
|
||||
cleanUpAndGo(server).then(deferred.resolve);
|
||||
});
|
||||
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
yield setUp(server);
|
||||
|
||||
// We're late for a sync...
|
||||
scheduler.scheduleNextSync(-1);
|
||||
yield deferred.promise;
|
||||
});
|
||||
|
||||
add_test(function test_scheduleNextSync_future_noBackoff() {
|
||||
add_identity_test(this, function test_scheduleNextSync_future_noBackoff() {
|
||||
_("scheduleNextSync() uses the current syncInterval if no interval is provided.");
|
||||
// Test backoffInterval is 0 as expected.
|
||||
do_check_eq(Status.backoffInterval, 0);
|
||||
@ -291,10 +299,10 @@ add_test(function test_scheduleNextSync_future_noBackoff() {
|
||||
do_check_true(scheduler.nextSync <= Date.now() + 1);
|
||||
do_check_eq(scheduler.syncTimer.delay, 1);
|
||||
|
||||
cleanUpAndGo();
|
||||
yield cleanUpAndGo();
|
||||
});
|
||||
|
||||
add_test(function test_scheduleNextSync_future_backoff() {
|
||||
add_identity_test(this, function test_scheduleNextSync_future_backoff() {
|
||||
_("scheduleNextSync() will honour backoff in all scheduling requests.");
|
||||
// Let's take a backoff interval that's bigger than the default sync interval.
|
||||
const BACKOFF = 7337;
|
||||
@ -341,12 +349,12 @@ add_test(function test_scheduleNextSync_future_backoff() {
|
||||
do_check_true(scheduler.nextSync <= Date.now() + Status.backoffInterval);
|
||||
do_check_eq(scheduler.syncTimer.delay, Status.backoffInterval);
|
||||
|
||||
cleanUpAndGo();
|
||||
yield cleanUpAndGo();
|
||||
});
|
||||
|
||||
add_test(function test_handleSyncError() {
|
||||
add_identity_test(this, function test_handleSyncError() {
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
yield setUp(server);
|
||||
|
||||
// Force sync to fail.
|
||||
Svc.Prefs.set("firstSync", "notReady");
|
||||
@ -399,12 +407,12 @@ add_test(function test_handleSyncError() {
|
||||
do_check_true(Status.enforceBackoff);
|
||||
scheduler.syncTimer.clear();
|
||||
|
||||
cleanUpAndGo(server);
|
||||
yield cleanUpAndGo(server);
|
||||
});
|
||||
|
||||
add_test(function test_client_sync_finish_updateClientMode() {
|
||||
add_identity_test(this, function test_client_sync_finish_updateClientMode() {
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
yield setUp(server);
|
||||
|
||||
// Confirm defaults.
|
||||
do_check_eq(scheduler.syncThreshold, SINGLE_USER_THRESHOLD);
|
||||
@ -433,24 +441,27 @@ add_test(function test_client_sync_finish_updateClientMode() {
|
||||
do_check_false(scheduler.numClients > 1);
|
||||
do_check_false(scheduler.idle);
|
||||
|
||||
cleanUpAndGo(server);
|
||||
yield cleanUpAndGo(server);
|
||||
});
|
||||
|
||||
add_test(function test_autoconnect_nextSync_past() {
|
||||
add_identity_test(this, function test_autoconnect_nextSync_past() {
|
||||
let deferred = Promise.defer();
|
||||
// nextSync will be 0 by default, so it's way in the past.
|
||||
|
||||
Svc.Obs.add("weave:service:sync:finish", function onSyncFinish() {
|
||||
Svc.Obs.remove("weave:service:sync:finish", onSyncFinish);
|
||||
cleanUpAndGo(server);
|
||||
cleanUpAndGo(server).then(deferred.resolve);
|
||||
});
|
||||
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
yield setUp(server);
|
||||
|
||||
scheduler.delayedAutoConnect(0);
|
||||
yield deferred.promise;
|
||||
});
|
||||
|
||||
add_test(function test_autoconnect_nextSync_future() {
|
||||
add_identity_test(this, function test_autoconnect_nextSync_future() {
|
||||
let deferred = Promise.defer();
|
||||
let previousSync = Date.now() + scheduler.syncInterval / 2;
|
||||
scheduler.nextSync = previousSync;
|
||||
// nextSync rounds to the nearest second.
|
||||
@ -468,16 +479,19 @@ add_test(function test_autoconnect_nextSync_future() {
|
||||
do_check_true(scheduler.syncTimer.delay >= expectedInterval);
|
||||
|
||||
Svc.Obs.remove("weave:service:login:start", onLoginStart);
|
||||
cleanUpAndGo();
|
||||
cleanUpAndGo().then(deferred.resolve);
|
||||
});
|
||||
|
||||
setBasicCredentials("johndoe", "ilovejane", "abcdeabcdeabcdeabcdeabcdea");
|
||||
yield configureIdentity({username: "johndoe"});
|
||||
scheduler.delayedAutoConnect(0);
|
||||
yield deferred.promise;
|
||||
});
|
||||
|
||||
add_test(function test_autoconnect_mp_locked() {
|
||||
// XXX - this test can't be run with the browserid identity as it relies
|
||||
// on the syncKey getter behaving in a certain way...
|
||||
add_task(function test_autoconnect_mp_locked() {
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
yield setUp(server);
|
||||
|
||||
// Pretend user did not unlock master password.
|
||||
let origLocked = Utils.mpLocked;
|
||||
@ -491,6 +505,7 @@ add_test(function test_autoconnect_mp_locked() {
|
||||
throw "User canceled Master Password entry";
|
||||
});
|
||||
|
||||
let deferred = Promise.defer();
|
||||
// A locked master password will still trigger a sync, but then we'll hit
|
||||
// MASTER_PASSWORD_LOCKED and hence MASTER_PASSWORD_LOCKED_RETRY_INTERVAL.
|
||||
Svc.Obs.add("weave:service:login:error", function onLoginError() {
|
||||
@ -503,16 +518,17 @@ add_test(function test_autoconnect_mp_locked() {
|
||||
Service.identity.__defineGetter__("syncKey", origGetter);
|
||||
Service.identity.__defineSetter__("syncKey", origSetter);
|
||||
|
||||
cleanUpAndGo(server);
|
||||
cleanUpAndGo(server).then(deferred.resolve);
|
||||
});
|
||||
});
|
||||
|
||||
scheduler.delayedAutoConnect(0);
|
||||
yield deferred.promise;
|
||||
});
|
||||
|
||||
add_test(function test_no_autoconnect_during_wizard() {
|
||||
add_identity_test(this, function test_no_autoconnect_during_wizard() {
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
yield setUp(server);
|
||||
|
||||
// Simulate the Sync setup wizard.
|
||||
Svc.Prefs.set("firstSync", "notReady");
|
||||
@ -523,15 +539,17 @@ add_test(function test_no_autoconnect_during_wizard() {
|
||||
}
|
||||
Svc.Obs.add("weave:service:login:start", onLoginStart);
|
||||
|
||||
let deferred = Promise.defer();
|
||||
waitForZeroTimer(function () {
|
||||
Svc.Obs.remove("weave:service:login:start", onLoginStart);
|
||||
cleanUpAndGo(server);
|
||||
cleanUpAndGo(server).then(deferred.resolve);
|
||||
});
|
||||
|
||||
scheduler.delayedAutoConnect(0);
|
||||
yield deferred.promise;
|
||||
});
|
||||
|
||||
add_test(function test_no_autoconnect_status_not_ok() {
|
||||
add_identity_test(this, function test_no_autoconnect_status_not_ok() {
|
||||
let server = sync_httpd_setup();
|
||||
|
||||
// Ensure we don't actually try to sync (or log in for that matter).
|
||||
@ -540,37 +558,41 @@ add_test(function test_no_autoconnect_status_not_ok() {
|
||||
}
|
||||
Svc.Obs.add("weave:service:login:start", onLoginStart);
|
||||
|
||||
let deferred = Promise.defer();
|
||||
waitForZeroTimer(function () {
|
||||
Svc.Obs.remove("weave:service:login:start", onLoginStart);
|
||||
|
||||
do_check_eq(Status.service, CLIENT_NOT_CONFIGURED);
|
||||
do_check_eq(Status.login, LOGIN_FAILED_NO_USERNAME);
|
||||
|
||||
cleanUpAndGo(server);
|
||||
cleanUpAndGo(server).then(deferred.resolve);
|
||||
});
|
||||
|
||||
scheduler.delayedAutoConnect(0);
|
||||
yield deferred.promise;
|
||||
});
|
||||
|
||||
add_test(function test_autoconnectDelay_pref() {
|
||||
add_identity_test(this, function test_autoconnectDelay_pref() {
|
||||
let deferred = Promise.defer();
|
||||
Svc.Obs.add("weave:service:sync:finish", function onSyncFinish() {
|
||||
Svc.Obs.remove("weave:service:sync:finish", onSyncFinish);
|
||||
cleanUpAndGo(server);
|
||||
cleanUpAndGo(server).then(deferred.resolve);
|
||||
});
|
||||
|
||||
Svc.Prefs.set("autoconnectDelay", 1);
|
||||
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
yield setUp(server);
|
||||
|
||||
Svc.Obs.notify("weave:service:ready");
|
||||
|
||||
// autoconnectDelay pref is multiplied by 1000.
|
||||
do_check_eq(scheduler._autoTimer.delay, 1000);
|
||||
do_check_eq(Status.service, STATUS_OK);
|
||||
yield deferred.promise;
|
||||
});
|
||||
|
||||
add_test(function test_idle_adjustSyncInterval() {
|
||||
add_identity_test(this, function test_idle_adjustSyncInterval() {
|
||||
// Confirm defaults.
|
||||
do_check_eq(scheduler.idle, false);
|
||||
|
||||
@ -587,10 +609,10 @@ add_test(function test_idle_adjustSyncInterval() {
|
||||
do_check_eq(scheduler.idle, true);
|
||||
do_check_eq(scheduler.syncInterval, scheduler.idleInterval);
|
||||
|
||||
cleanUpAndGo();
|
||||
yield cleanUpAndGo();
|
||||
});
|
||||
|
||||
add_test(function test_back_triggersSync() {
|
||||
add_identity_test(this, function test_back_triggersSync() {
|
||||
// Confirm defaults.
|
||||
do_check_false(scheduler.idle);
|
||||
do_check_eq(Status.backoffInterval, 0);
|
||||
@ -600,18 +622,20 @@ add_test(function test_back_triggersSync() {
|
||||
scheduler.observe(null, "idle", Svc.Prefs.get("scheduler.idleTime"));
|
||||
do_check_true(scheduler.idle);
|
||||
|
||||
let deferred = Promise.defer();
|
||||
// We don't actually expect the sync (or the login, for that matter) to
|
||||
// succeed. We just want to ensure that it was attempted.
|
||||
Svc.Obs.add("weave:service:login:error", function onLoginError() {
|
||||
Svc.Obs.remove("weave:service:login:error", onLoginError);
|
||||
cleanUpAndGo();
|
||||
cleanUpAndGo().then(deferred.resolve);
|
||||
});
|
||||
|
||||
// Send a 'back' event to trigger sync soonish.
|
||||
scheduler.observe(null, "back", Svc.Prefs.get("scheduler.idleTime"));
|
||||
yield deferred.promise;
|
||||
});
|
||||
|
||||
add_test(function test_back_triggersSync_observesBackoff() {
|
||||
add_identity_test(this, function test_back_triggersSync_observesBackoff() {
|
||||
// Confirm defaults.
|
||||
do_check_false(scheduler.idle);
|
||||
|
||||
@ -627,20 +651,22 @@ add_test(function test_back_triggersSync_observesBackoff() {
|
||||
}
|
||||
Svc.Obs.add("weave:service:login:start", onLoginStart);
|
||||
|
||||
let deferred = Promise.defer();
|
||||
timer = Utils.namedTimer(function () {
|
||||
Svc.Obs.remove("weave:service:login:start", onLoginStart);
|
||||
|
||||
do_check_true(scheduler.nextSync <= Date.now() + Status.backoffInterval);
|
||||
do_check_eq(scheduler.syncTimer.delay, Status.backoffInterval);
|
||||
|
||||
cleanUpAndGo();
|
||||
cleanUpAndGo().then(deferred.resolve);
|
||||
}, IDLE_OBSERVER_BACK_DELAY * 1.5, {}, "timer");
|
||||
|
||||
// Send a 'back' event to try to trigger sync soonish.
|
||||
scheduler.observe(null, "back", Svc.Prefs.get("scheduler.idleTime"));
|
||||
yield deferred.promise;
|
||||
});
|
||||
|
||||
add_test(function test_back_debouncing() {
|
||||
add_identity_test(this, function test_back_debouncing() {
|
||||
_("Ensure spurious back-then-idle events, as observed on OS X, don't trigger a sync.");
|
||||
|
||||
// Confirm defaults.
|
||||
@ -660,17 +686,19 @@ add_test(function test_back_debouncing() {
|
||||
scheduler.observe(null, "back", Svc.Prefs.get("scheduler.idleTime"));
|
||||
scheduler.observe(null, "idle", Svc.Prefs.get("scheduler.idleTime"));
|
||||
|
||||
let deferred = Promise.defer();
|
||||
timer = Utils.namedTimer(function () {
|
||||
Svc.Obs.remove("weave:service:login:start", onLoginStart);
|
||||
cleanUpAndGo();
|
||||
cleanUpAndGo().then(deferred.resolve);
|
||||
}, IDLE_OBSERVER_BACK_DELAY * 1.5, {}, "timer");
|
||||
yield deferred.promise;
|
||||
});
|
||||
|
||||
add_test(function test_no_sync_node() {
|
||||
add_identity_test(this, function test_no_sync_node() {
|
||||
// Test when Status.sync == NO_SYNC_NODE_FOUND
|
||||
// it is not overwritten on sync:finish
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
yield setUp(server);
|
||||
|
||||
Service.serverURL = server.baseURI + "/";
|
||||
|
||||
@ -678,10 +706,10 @@ add_test(function test_no_sync_node() {
|
||||
do_check_eq(Status.sync, NO_SYNC_NODE_FOUND);
|
||||
do_check_eq(scheduler.syncTimer.delay, NO_SYNC_NODE_INTERVAL);
|
||||
|
||||
cleanUpAndGo(server);
|
||||
yield cleanUpAndGo(server);
|
||||
});
|
||||
|
||||
add_test(function test_sync_failed_partial_500s() {
|
||||
add_identity_test(this, function test_sync_failed_partial_500s() {
|
||||
_("Test a 5xx status calls handleSyncError.");
|
||||
scheduler._syncErrors = MAX_ERROR_COUNT_BEFORE_BACKOFF;
|
||||
let server = sync_httpd_setup();
|
||||
@ -692,7 +720,7 @@ add_test(function test_sync_failed_partial_500s() {
|
||||
|
||||
do_check_eq(Status.sync, SYNC_SUCCEEDED);
|
||||
|
||||
do_check_true(setUp(server));
|
||||
do_check_true(yield setUp(server));
|
||||
|
||||
Service.sync();
|
||||
|
||||
@ -705,10 +733,10 @@ add_test(function test_sync_failed_partial_500s() {
|
||||
do_check_true(scheduler.nextSync <= (Date.now() + maxInterval));
|
||||
do_check_true(scheduler.syncTimer.delay <= maxInterval);
|
||||
|
||||
cleanUpAndGo(server);
|
||||
yield cleanUpAndGo(server);
|
||||
});
|
||||
|
||||
add_test(function test_sync_failed_partial_400s() {
|
||||
add_identity_test(this, function test_sync_failed_partial_400s() {
|
||||
_("Test a non-5xx status doesn't call handleSyncError.");
|
||||
scheduler._syncErrors = MAX_ERROR_COUNT_BEFORE_BACKOFF;
|
||||
let server = sync_httpd_setup();
|
||||
@ -722,7 +750,7 @@ add_test(function test_sync_failed_partial_400s() {
|
||||
|
||||
do_check_eq(Status.sync, SYNC_SUCCEEDED);
|
||||
|
||||
do_check_true(setUp(server));
|
||||
do_check_true(yield setUp(server));
|
||||
|
||||
Service.sync();
|
||||
|
||||
@ -735,12 +763,12 @@ add_test(function test_sync_failed_partial_400s() {
|
||||
do_check_true(scheduler.nextSync <= (Date.now() + scheduler.activeInterval));
|
||||
do_check_true(scheduler.syncTimer.delay <= scheduler.activeInterval);
|
||||
|
||||
cleanUpAndGo(server);
|
||||
yield cleanUpAndGo(server);
|
||||
});
|
||||
|
||||
add_test(function test_sync_X_Weave_Backoff() {
|
||||
add_identity_test(this, function test_sync_X_Weave_Backoff() {
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
yield setUp(server);
|
||||
|
||||
// Use an odd value on purpose so that it doesn't happen to coincide with one
|
||||
// of the sync intervals.
|
||||
@ -790,12 +818,12 @@ add_test(function test_sync_X_Weave_Backoff() {
|
||||
do_check_true(scheduler.nextSync >= Date.now() + minimumExpectedDelay);
|
||||
do_check_true(scheduler.syncTimer.delay >= minimumExpectedDelay);
|
||||
|
||||
cleanUpAndGo(server);
|
||||
yield cleanUpAndGo(server);
|
||||
});
|
||||
|
||||
add_test(function test_sync_503_Retry_After() {
|
||||
add_identity_test(this, function test_sync_503_Retry_After() {
|
||||
let server = sync_httpd_setup();
|
||||
setUp(server);
|
||||
yield setUp(server);
|
||||
|
||||
// Use an odd value on purpose so that it doesn't happen to coincide with one
|
||||
// of the sync intervals.
|
||||
@ -849,17 +877,18 @@ add_test(function test_sync_503_Retry_After() {
|
||||
do_check_true(scheduler.nextSync >= Date.now() + minimumExpectedDelay);
|
||||
do_check_true(scheduler.syncTimer.delay >= minimumExpectedDelay);
|
||||
|
||||
cleanUpAndGo(server);
|
||||
yield cleanUpAndGo(server);
|
||||
});
|
||||
|
||||
add_test(function test_loginError_recoverable_reschedules() {
|
||||
add_identity_test(this, function test_loginError_recoverable_reschedules() {
|
||||
_("Verify that a recoverable login error schedules a new sync.");
|
||||
setBasicCredentials("johndoe", "ilovejane", "abcdeabcdeabcdeabcdeabcdea");
|
||||
yield configureIdentity({username: "johndoe"});
|
||||
Service.serverURL = "http://localhost:1234/";
|
||||
Service.clusterURL = Service.serverURL;
|
||||
Service.persistLogin();
|
||||
Status.resetSync(); // reset Status.login
|
||||
|
||||
let deferred = Promise.defer();
|
||||
Svc.Obs.add("weave:service:login:error", function onLoginError() {
|
||||
Svc.Obs.remove("weave:service:login:error", onLoginError);
|
||||
Utils.nextTick(function aLittleBitAfterLoginError() {
|
||||
@ -872,7 +901,7 @@ add_test(function test_loginError_recoverable_reschedules() {
|
||||
do_check_true(scheduler.syncTimer.delay <= scheduler.syncInterval);
|
||||
|
||||
Svc.Obs.remove("weave:service:sync:start", onSyncStart);
|
||||
cleanUpAndGo();
|
||||
cleanUpAndGo().then(deferred.resolve);
|
||||
});
|
||||
});
|
||||
|
||||
@ -892,11 +921,12 @@ add_test(function test_loginError_recoverable_reschedules() {
|
||||
do_check_eq(Status.login, LOGIN_SUCCEEDED);
|
||||
|
||||
scheduler.scheduleNextSync(0);
|
||||
yield deferred.promise;
|
||||
});
|
||||
|
||||
add_test(function test_loginError_fatal_clearsTriggers() {
|
||||
add_identity_test(this, function test_loginError_fatal_clearsTriggers() {
|
||||
_("Verify that a fatal login error clears sync triggers.");
|
||||
setBasicCredentials("johndoe", "ilovejane", "abcdeabcdeabcdeabcdeabcdea");
|
||||
yield configureIdentity({username: "johndoe"});
|
||||
|
||||
let server = httpd_setup({
|
||||
"/1.1/johndoe/info/collections": httpd_handler(401, "Unauthorized")
|
||||
@ -907,6 +937,7 @@ add_test(function test_loginError_fatal_clearsTriggers() {
|
||||
Service.persistLogin();
|
||||
Status.resetSync(); // reset Status.login
|
||||
|
||||
let deferred = Promise.defer();
|
||||
Svc.Obs.add("weave:service:login:error", function onLoginError() {
|
||||
Svc.Obs.remove("weave:service:login:error", onLoginError);
|
||||
Utils.nextTick(function aLittleBitAfterLoginError() {
|
||||
@ -915,7 +946,7 @@ add_test(function test_loginError_fatal_clearsTriggers() {
|
||||
do_check_eq(scheduler.nextSync, 0);
|
||||
do_check_eq(scheduler.syncTimer, null);
|
||||
|
||||
cleanUpAndGo(server);
|
||||
cleanUpAndGo(server).then(deferred.resolve);
|
||||
});
|
||||
});
|
||||
|
||||
@ -926,9 +957,10 @@ add_test(function test_loginError_fatal_clearsTriggers() {
|
||||
do_check_eq(Status.login, LOGIN_SUCCEEDED);
|
||||
|
||||
scheduler.scheduleNextSync(0);
|
||||
yield deferred.promise;
|
||||
});
|
||||
|
||||
add_test(function test_proper_interval_on_only_failing() {
|
||||
add_identity_test(this, function test_proper_interval_on_only_failing() {
|
||||
_("Ensure proper behavior when only failed records are applied.");
|
||||
|
||||
// If an engine reports that no records succeeded, we shouldn't decrease the
|
||||
@ -945,11 +977,13 @@ add_test(function test_proper_interval_on_only_failing() {
|
||||
reconciled: 0
|
||||
});
|
||||
|
||||
let deferred = Promise.defer();
|
||||
Utils.nextTick(function() {
|
||||
scheduler.adjustSyncInterval();
|
||||
do_check_false(scheduler.hasIncomingItems);
|
||||
do_check_eq(scheduler.syncInterval, scheduler.singleDeviceInterval);
|
||||
|
||||
run_next_test();
|
||||
deferred.resolve();
|
||||
});
|
||||
yield deferred.promise;
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user