Bug 1415012 - Don't trigger a resync if the previous sync wasn't completely successful r?kitcambridge
MozReview-Commit-ID: DcNsFUxXR1O
--- a/services/sync/modules/policies.js
+++ b/services/sync/modules/policies.js
@@ -170,17 +170,17 @@ SyncScheduler.prototype = {
if (Status.service == SYNC_FAILED_PARTIAL && this.requiresBackoff) {
this.requiresBackoff = false;
this.handleSyncError();
return;
}
let sync_interval;
this.updateGlobalScore();
- if (this.globalScore > 0) {
+ if (this.globalScore > 0 && Status.service == STATUS_OK) {
// The global score should be 0 after a sync. If it's not, items were
// changed during the last sync, and we should schedule an immediate
// follow-up sync.
this._resyncs++;
if (this._resyncs <= this.maxResyncs) {
sync_interval = 0;
} else {
this._log.warn(`Resync attempt ${this._resyncs} exceeded ` +
--- a/services/sync/tests/unit/test_syncscheduler.js
+++ b/services/sync/tests/unit/test_syncscheduler.js
@@ -751,16 +751,47 @@ add_task(async function test_sync_failed
do_check_true(Status.enforceBackoff);
do_check_eq(scheduler._syncErrors, 4);
do_check_true(scheduler.nextSync <= (Date.now() + maxInterval));
do_check_true(scheduler.syncTimer.delay <= maxInterval);
await cleanUpAndGo(server);
});
+add_task(async function test_sync_failed_partial_noresync() {
+ enableValidationPrefs();
+ let server = sync_httpd_setup();
+
+ let engine = Service.engineManager.get("catapult");
+ engine.enabled = true;
+ engine.exception = "Bad news";
+ engine._tracker._score = 10;
+
+ do_check_eq(Status.sync, SYNC_SUCCEEDED);
+
+ do_check_true(await setUp(server));
+
+ let resyncDoneObserver = promiseOneObserver("weave:service:resyncs-finished");
+
+ await Service.sync();
+
+ do_check_eq(Status.service, SYNC_FAILED_PARTIAL);
+
+ function onSyncStarted() {
+ do_throw("Should not start resync when previous sync failed");
+ }
+
+ Svc.Obs.add("weave:service:sync:start", onSyncStarted);
+ await resyncDoneObserver;
+
+ Svc.Obs.remove("weave:service:sync:start", onSyncStarted);
+ engine._tracker._store = 0;
+ await cleanUpAndGo(server);
+});
+
add_task(async function test_sync_failed_partial_400s() {
enableValidationPrefs();
_("Test a non-5xx status doesn't call handleSyncError.");
scheduler._syncErrors = MAX_ERROR_COUNT_BEFORE_BACKOFF;
let server = sync_httpd_setup();
let engine = Service.engineManager.get("catapult");