summaryrefslogtreecommitdiffstats
path: root/services/sync/tests/unit/test_syncscheduler.js
diff options
context:
space:
mode:
Diffstat (limited to 'services/sync/tests/unit/test_syncscheduler.js')
-rw-r--r--services/sync/tests/unit/test_syncscheduler.js113
1 files changed, 42 insertions, 71 deletions
diff --git a/services/sync/tests/unit/test_syncscheduler.js b/services/sync/tests/unit/test_syncscheduler.js
index 730a3f996..d496b8838 100644
--- a/services/sync/tests/unit/test_syncscheduler.js
+++ b/services/sync/tests/unit/test_syncscheduler.js
@@ -26,13 +26,8 @@ CatapultEngine.prototype = {
Service.engineManager.register(CatapultEngine);
-var scheduler = new SyncScheduler(Service);
-var clientsEngine = Service.clientsEngine;
-
-// Don't remove stale clients when syncing. This is a test-only workaround
-// that lets us add clients directly to the store, without losing them on
-// the next sync.
-clientsEngine._removeRemoteClient = id => {};
+let scheduler = new SyncScheduler(Service);
+let clientsEngine = Service.clientsEngine;
function sync_httpd_setup() {
let global = new ServerWBO("global", {
@@ -74,7 +69,6 @@ function setUp(server) {
function cleanUpAndGo(server) {
let deferred = Promise.defer();
Utils.nextTick(function () {
- clientsEngine._store.wipe();
Service.startOver();
if (server) {
server.stop(deferred.resolve);
@@ -90,7 +84,6 @@ function run_test() {
Log.repository.getLogger("Sync.Service").level = Log.Level.Trace;
Log.repository.getLogger("Sync.scheduler").level = Log.Level.Trace;
- validate_all_future_pings();
// The scheduler checks Weave.fxaEnabled to determine whether to use
// FxA defaults or legacy defaults. As .fxaEnabled checks the username, we
@@ -148,33 +141,22 @@ add_test(function test_prefAttributes() {
Svc.Prefs.get("scheduler.immediateInterval") * 1000);
_("Custom values for prefs will take effect after a restart.");
- Svc.Prefs.set("scheduler.sync11.singleDeviceInterval", 420);
- Svc.Prefs.set("scheduler.idleInterval", 230);
- Svc.Prefs.set("scheduler.activeInterval", 180);
+ Svc.Prefs.set("scheduler.sync11.singleDeviceInterval", 42);
+ Svc.Prefs.set("scheduler.idleInterval", 23);
+ Svc.Prefs.set("scheduler.activeInterval", 18);
Svc.Prefs.set("scheduler.immediateInterval", 31415);
scheduler.setDefaults();
- do_check_eq(scheduler.idleInterval, 230000);
- do_check_eq(scheduler.singleDeviceInterval, 420000);
- do_check_eq(scheduler.activeInterval, 180000);
+ do_check_eq(scheduler.idleInterval, 23000);
+ do_check_eq(scheduler.singleDeviceInterval, 42000);
+ do_check_eq(scheduler.activeInterval, 18000);
do_check_eq(scheduler.immediateInterval, 31415000);
- _("Custom values for interval prefs can't be less than 60 seconds.");
- Svc.Prefs.set("scheduler.sync11.singleDeviceInterval", 42);
- Svc.Prefs.set("scheduler.idleInterval", 50);
- Svc.Prefs.set("scheduler.activeInterval", 50);
- Svc.Prefs.set("scheduler.immediateInterval", 10);
- scheduler.setDefaults();
- do_check_eq(scheduler.idleInterval, 60000);
- do_check_eq(scheduler.singleDeviceInterval, 60000);
- do_check_eq(scheduler.activeInterval, 60000);
- do_check_eq(scheduler.immediateInterval, 60000);
-
Svc.Prefs.resetBranch("");
scheduler.setDefaults();
run_next_test();
});
-add_identity_test(this, 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);
@@ -204,7 +186,7 @@ add_identity_test(this, function* test_updateClientMode() {
yield cleanUpAndGo();
});
-add_identity_test(this, 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() {
@@ -241,7 +223,7 @@ add_identity_test(this, function* test_masterpassword_locked_retry_interval() {
yield cleanUpAndGo(server);
});
-add_identity_test(this, 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
@@ -263,7 +245,7 @@ add_identity_test(this, function* test_calculateBackoff() {
yield cleanUpAndGo();
});
-add_identity_test(this, 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);
@@ -278,7 +260,7 @@ add_identity_test(this, function* test_scheduleNextSync_nowOrPast() {
yield deferred.promise;
});
-add_identity_test(this, 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);
@@ -327,7 +309,7 @@ add_identity_test(this, function* test_scheduleNextSync_future_noBackoff() {
yield cleanUpAndGo();
});
-add_identity_test(this, 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;
@@ -377,7 +359,7 @@ add_identity_test(this, function* test_scheduleNextSync_future_backoff() {
yield cleanUpAndGo();
});
-add_identity_test(this, function* test_handleSyncError() {
+add_identity_test(this, function test_handleSyncError() {
let server = sync_httpd_setup();
yield setUp(server);
@@ -443,7 +425,7 @@ add_identity_test(this, function* test_handleSyncError() {
yield deferred.promise;
});
-add_identity_test(this, function* test_client_sync_finish_updateClientMode() {
+add_identity_test(this, function test_client_sync_finish_updateClientMode() {
let server = sync_httpd_setup();
yield setUp(server);
@@ -477,7 +459,7 @@ add_identity_test(this, function* test_client_sync_finish_updateClientMode() {
yield cleanUpAndGo(server);
});
-add_identity_test(this, 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.
@@ -493,7 +475,7 @@ add_identity_test(this, function* test_autoconnect_nextSync_past() {
yield deferred.promise;
});
-add_identity_test(this, 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;
@@ -522,7 +504,7 @@ add_identity_test(this, function* test_autoconnect_nextSync_future() {
// 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() {
+add_task(function test_autoconnect_mp_locked() {
let server = sync_httpd_setup();
yield setUp(server);
@@ -559,7 +541,7 @@ add_task(function* test_autoconnect_mp_locked() {
yield deferred.promise;
});
-add_identity_test(this, function* test_no_autoconnect_during_wizard() {
+add_identity_test(this, function test_no_autoconnect_during_wizard() {
let server = sync_httpd_setup();
yield setUp(server);
@@ -582,7 +564,7 @@ add_identity_test(this, function* test_no_autoconnect_during_wizard() {
yield deferred.promise;
});
-add_identity_test(this, 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).
@@ -605,7 +587,7 @@ add_identity_test(this, function* test_no_autoconnect_status_not_ok() {
yield deferred.promise;
});
-add_identity_test(this, 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);
@@ -625,7 +607,7 @@ add_identity_test(this, function* test_autoconnectDelay_pref() {
yield deferred.promise;
});
-add_identity_test(this, function* test_idle_adjustSyncInterval() {
+add_identity_test(this, function test_idle_adjustSyncInterval() {
// Confirm defaults.
do_check_eq(scheduler.idle, false);
@@ -645,7 +627,7 @@ add_identity_test(this, function* test_idle_adjustSyncInterval() {
yield cleanUpAndGo();
});
-add_identity_test(this, 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);
@@ -668,7 +650,7 @@ add_identity_test(this, function* test_back_triggersSync() {
yield deferred.promise;
});
-add_identity_test(this, function* test_active_triggersSync_observesBackoff() {
+add_identity_test(this, function test_active_triggersSync_observesBackoff() {
// Confirm defaults.
do_check_false(scheduler.idle);
@@ -699,7 +681,7 @@ add_identity_test(this, function* test_active_triggersSync_observesBackoff() {
yield deferred.promise;
});
-add_identity_test(this, 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.
@@ -727,7 +709,7 @@ add_identity_test(this, function* test_back_debouncing() {
yield deferred.promise;
});
-add_identity_test(this, 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();
@@ -742,7 +724,7 @@ add_identity_test(this, function* test_no_sync_node() {
yield cleanUpAndGo(server);
});
-add_identity_test(this, 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();
@@ -769,7 +751,7 @@ add_identity_test(this, function* test_sync_failed_partial_500s() {
yield cleanUpAndGo(server);
});
-add_identity_test(this, 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();
@@ -799,7 +781,7 @@ add_identity_test(this, function* test_sync_failed_partial_400s() {
yield cleanUpAndGo(server);
});
-add_identity_test(this, function* test_sync_X_Weave_Backoff() {
+add_identity_test(this, function test_sync_X_Weave_Backoff() {
let server = sync_httpd_setup();
yield setUp(server);
@@ -842,9 +824,9 @@ add_identity_test(this, function* test_sync_X_Weave_Backoff() {
Service.sync();
do_check_true(Status.backoffInterval >= BACKOFF * 1000);
- // Allowing 3 seconds worth of of leeway between when Status.minimumNextSync
+ // Allowing 1 second worth of of leeway between when Status.minimumNextSync
// was set and when this line gets executed.
- let minimumExpectedDelay = (BACKOFF - 3) * 1000;
+ let minimumExpectedDelay = (BACKOFF - 1) * 1000;
do_check_true(Status.minimumNextSync >= Date.now() + minimumExpectedDelay);
// Verify that the next sync is actually going to wait that long.
@@ -854,7 +836,7 @@ add_identity_test(this, function* test_sync_X_Weave_Backoff() {
yield cleanUpAndGo(server);
});
-add_identity_test(this, function* test_sync_503_Retry_After() {
+add_identity_test(this, function test_sync_503_Retry_After() {
let server = sync_httpd_setup();
yield setUp(server);
@@ -901,9 +883,9 @@ add_identity_test(this, function* test_sync_503_Retry_After() {
do_check_true(Status.enforceBackoff);
do_check_true(Status.backoffInterval >= BACKOFF * 1000);
- // Allowing 3 seconds worth of of leeway between when Status.minimumNextSync
+ // Allowing 1 second worth of of leeway between when Status.minimumNextSync
// was set and when this line gets executed.
- let minimumExpectedDelay = (BACKOFF - 3) * 1000;
+ let minimumExpectedDelay = (BACKOFF - 1) * 1000;
do_check_true(Status.minimumNextSync >= Date.now() + minimumExpectedDelay);
// Verify that the next sync is actually going to wait that long.
@@ -913,7 +895,7 @@ add_identity_test(this, function* test_sync_503_Retry_After() {
yield cleanUpAndGo(server);
});
-add_identity_test(this, function* test_loginError_recoverable_reschedules() {
+add_identity_test(this, function test_loginError_recoverable_reschedules() {
_("Verify that a recoverable login error schedules a new sync.");
yield configureIdentity({username: "johndoe"});
Service.serverURL = "http://localhost:1234/";
@@ -957,7 +939,7 @@ add_identity_test(this, function* test_loginError_recoverable_reschedules() {
yield deferred.promise;
});
-add_identity_test(this, function* test_loginError_fatal_clearsTriggers() {
+add_identity_test(this, function test_loginError_fatal_clearsTriggers() {
_("Verify that a fatal login error clears sync triggers.");
yield configureIdentity({username: "johndoe"});
@@ -974,22 +956,11 @@ add_identity_test(this, function* test_loginError_fatal_clearsTriggers() {
Svc.Obs.add("weave:service:login:error", function onLoginError() {
Svc.Obs.remove("weave:service:login:error", onLoginError);
Utils.nextTick(function aLittleBitAfterLoginError() {
+ do_check_eq(Status.login, LOGIN_FAILED_LOGIN_REJECTED);
+
+ do_check_eq(scheduler.nextSync, 0);
+ do_check_eq(scheduler.syncTimer, null);
- if (isConfiguredWithLegacyIdentity()) {
- // for the "legacy" identity, a 401 on info/collections means the
- // password is wrong, so we enter a "login rejected" state.
- do_check_eq(Status.login, LOGIN_FAILED_LOGIN_REJECTED);
-
- do_check_eq(scheduler.nextSync, 0);
- do_check_eq(scheduler.syncTimer, null);
- } else {
- // For the FxA identity, a 401 on info/collections means a transient
- // error, probably due to an inability to fetch a token.
- do_check_eq(Status.login, LOGIN_FAILED_NETWORK_ERROR);
- // syncs should still be scheduled.
- do_check_true(scheduler.nextSync > Date.now());
- do_check_true(scheduler.syncTimer.delay > 0);
- }
cleanUpAndGo(server).then(deferred.resolve);
});
});
@@ -1004,7 +975,7 @@ add_identity_test(this, function* test_loginError_fatal_clearsTriggers() {
yield deferred.promise;
});
-add_identity_test(this, 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