зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1019408 - add facility to block and unblock new syncs starting. r=rnewman
This commit is contained in:
Родитель
725a5d76d6
Коммит
d59ff25498
|
@ -301,19 +301,11 @@ Migrator.prototype = {
|
|||
|
||||
// Prevent sync from automatically starting
|
||||
_blockSync() {
|
||||
if (Weave.Service.scheduler.blockSync) {
|
||||
Weave.Service.scheduler.blockSync();
|
||||
} else {
|
||||
this.log.warn("Waiting on bug 1019408; sync not blocked");
|
||||
}
|
||||
Weave.Service.scheduler.blockSync();
|
||||
},
|
||||
|
||||
_unblockSync() {
|
||||
if (Weave.Service.scheduler.unblockSync) {
|
||||
Weave.Service.scheduler.unblockSync();
|
||||
} else {
|
||||
this.log.warn("Waiting on bug 1019408; sync not unblocked");
|
||||
}
|
||||
Weave.Service.scheduler.unblockSync();
|
||||
},
|
||||
|
||||
/*
|
||||
|
|
|
@ -54,6 +54,9 @@ HMAC_EVENT_INTERVAL: 600000,
|
|||
// How long to wait between sync attempts if the Master Password is locked.
|
||||
MASTER_PASSWORD_LOCKED_RETRY_INTERVAL: 15 * 60 * 1000, // 15 minutes
|
||||
|
||||
// The default for how long we "block" sync from running when doing a migration.
|
||||
DEFAULT_BLOCK_PERIOD: 2 * 24 * 60 * 60 * 1000, // 2 days
|
||||
|
||||
// Separate from the ID fetch batch size to allow tuning for mobile.
|
||||
MOBILE_BATCH_SIZE: 50,
|
||||
|
||||
|
|
|
@ -497,6 +497,46 @@ SyncScheduler.prototype = {
|
|||
if (this.syncTimer)
|
||||
this.syncTimer.clear();
|
||||
},
|
||||
|
||||
/**
|
||||
* Prevent new syncs from starting. This is used by the FxA migration code
|
||||
* where we can't afford to have a sync start partway through the migration.
|
||||
* To handle the edge-case of a sync starting and not stopping, we store
|
||||
* this state in a pref, so on the next startup we remain blocked (and thus
|
||||
* sync will never start) so the migration can complete.
|
||||
*
|
||||
* As a safety measure, we only block for some period of time, and after
|
||||
* that it will automatically unblock. This ensures that if things go
|
||||
* really pear-shaped and we never end up calling unblockSync() we haven't
|
||||
* completely broken the world.
|
||||
*/
|
||||
blockSync: function(until = null) {
|
||||
if (!until) {
|
||||
until = Date.now() + DEFAULT_BLOCK_PERIOD;
|
||||
}
|
||||
// until is specified in ms, but Prefs can't hold that much
|
||||
Svc.Prefs.set("scheduler.blocked-until", Math.floor(until / 1000));
|
||||
},
|
||||
|
||||
unblockSync: function() {
|
||||
Svc.Prefs.reset("scheduler.blocked-until");
|
||||
// the migration code should be ready to roll, so resume normal operations.
|
||||
this.checkSyncStatus();
|
||||
},
|
||||
|
||||
get isBlocked() {
|
||||
let until = Svc.Prefs.get("scheduler.blocked-until");
|
||||
if (until === undefined) {
|
||||
return false;
|
||||
}
|
||||
if (until <= Math.floor(Date.now() / 1000)) {
|
||||
// we were previously blocked but the time has expired.
|
||||
Svc.Prefs.reset("scheduler.blocked-until");
|
||||
return false;
|
||||
}
|
||||
// we remain blocked.
|
||||
return true;
|
||||
},
|
||||
};
|
||||
|
||||
const LOG_PREFIX_SUCCESS = "success-";
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
Cu.import("resource://services-sync/main.js");
|
||||
Cu.import("resource://services-sync/util.js");
|
||||
|
||||
// Simple test for block/unblock.
|
||||
add_task(function *() {
|
||||
Assert.ok(!Weave.Service.scheduler.isBlocked, "sync is not blocked.")
|
||||
Assert.ok(!Svc.Prefs.has("scheduler.blocked-until"), "have no blocked pref");
|
||||
Weave.Service.scheduler.blockSync();
|
||||
|
||||
Assert.ok(Weave.Service.scheduler.isBlocked, "sync is blocked.")
|
||||
Assert.ok(Svc.Prefs.has("scheduler.blocked-until"), "have the blocked pref");
|
||||
|
||||
Weave.Service.scheduler.unblockSync();
|
||||
Assert.ok(!Weave.Service.scheduler.isBlocked, "sync is not blocked.")
|
||||
Assert.ok(!Svc.Prefs.has("scheduler.blocked-until"), "have no blocked pref");
|
||||
|
||||
// now check the "until" functionality.
|
||||
let until = Date.now() + 1000;
|
||||
Weave.Service.scheduler.blockSync(until);
|
||||
Assert.ok(Weave.Service.scheduler.isBlocked, "sync is blocked.")
|
||||
Assert.ok(Svc.Prefs.has("scheduler.blocked-until"), "have the blocked pref");
|
||||
|
||||
// wait for 'until' to pass.
|
||||
yield new Promise((resolve, reject) => {
|
||||
CommonUtils.namedTimer(resolve, 1000, {}, "timer");
|
||||
});
|
||||
|
||||
// should have automagically unblocked and removed the pref.
|
||||
Assert.ok(!Weave.Service.scheduler.isBlocked, "sync is not blocked.")
|
||||
Assert.ok(!Svc.Prefs.has("scheduler.blocked-until"), "have no blocked pref");
|
||||
});
|
||||
|
||||
function run_test() {
|
||||
run_next_test();
|
||||
}
|
|
@ -199,10 +199,7 @@ add_task(function *testMigration() {
|
|||
Assert.ok(!haveStartedSentinel, "haven't written a sentinel yet");
|
||||
|
||||
// sync should be blocked from continuing
|
||||
// (This is waiting on bug 1019408)
|
||||
/**
|
||||
Assert.ok(Service.scheduler.isBlocked, "sync is blocked.")
|
||||
**/
|
||||
|
||||
wasWaiting = true;
|
||||
throw ex;
|
||||
|
@ -227,10 +224,7 @@ add_task(function *testMigration() {
|
|||
|
||||
// The migration is now going to run to completion.
|
||||
// sync should still be "blocked"
|
||||
// (This is waiting on bug 1019408)
|
||||
/**
|
||||
Assert.ok(Service.scheduler.isBlocked, "sync is blocked.");
|
||||
**/
|
||||
|
||||
// We should see the migration sentinel written and it should return true.
|
||||
// (This is waiting on bug 1017433)
|
||||
|
|
|
@ -174,4 +174,5 @@ skip-if = ! healthreport
|
|||
[test_warn_on_truncated_response.js]
|
||||
|
||||
# FxA migration
|
||||
[test_block_sync.js]
|
||||
[test_fxa_migration.js]
|
||||
|
|
Загрузка…
Ссылка в новой задаче