From dfa642bc63d9bd4a2ab53cdf26edff0bc1acb241 Mon Sep 17 00:00:00 2001 From: Mark Hammond Date: Mon, 20 Mar 2017 19:13:42 +1100 Subject: [PATCH] Bug 1348743 - avoid running a bookmark validation on every sync. r=tcsc MozReview-Commit-ID: 49sWR56kfrj --HG-- extra : rebase_source : f13d7ef61b343820347579b76352cd65a322c8eb --- services/sync/modules/doctor.js | 2 +- services/sync/tests/unit/test_doctor.js | 47 +++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/services/sync/modules/doctor.js b/services/sync/modules/doctor.js index 252a7187a21d..0412dbfa0ac5 100644 --- a/services/sync/modules/doctor.js +++ b/services/sync/modules/doctor.js @@ -106,7 +106,7 @@ this.Doctor = { // Update the time now, even if we decline to actually perform a // validation. We don't want to check the rest of these more frequently // than once a day. - Svc.Prefs.set("validation.lastTime", Math.floor(nowSeconds)); + Svc.Prefs.set(prefPrefix + "validation.lastTime", Math.floor(nowSeconds)); // Validation only occurs a certain percentage of the time. let validationProbability = Svc.Prefs.get(prefPrefix + "validation.percentageChance", 0) / 100.0; diff --git a/services/sync/tests/unit/test_doctor.js b/services/sync/tests/unit/test_doctor.js index f8432d203466..25f9e33cdd8e 100644 --- a/services/sync/tests/unit/test_doctor.js +++ b/services/sync/tests/unit/test_doctor.js @@ -2,6 +2,7 @@ http://creativecommons.org/publicdomain/zero/1.0/ */ const { Doctor, REPAIR_ADVANCE_PERIOD } = Cu.import("resource://services-sync/doctor.js", {}); +Cu.import("resource://gre/modules/Services.jsm"); initTestLogging("Trace"); @@ -10,6 +11,52 @@ function mockDoctor(mocks) { return Object.assign({}, Doctor, mocks); } +add_task(async function test_validation_interval() { + let now = 1000; + let doctor = mockDoctor({ + _now() { + // note that the function being mocked actually returns seconds. + return now; + }, + }); + + let engine = { + name: "test-engine", + getValidator() { + return { + validate(e) { + return {}; + } + } + }, + } + + // setup prefs which enable test-engine validation. + Services.prefs.setBoolPref("services.sync.engine.test-engine.validation.enabled", true); + Services.prefs.setIntPref("services.sync.engine.test-engine.validation.percentageChance", 100); + Services.prefs.setIntPref("services.sync.engine.test-engine.validation.maxRecords", 1); + // And say we should validate every 10 seconds. + Services.prefs.setIntPref("services.sync.engine.test-engine.validation.interval", 10); + + deepEqual(doctor._getEnginesToValidate([engine]), { + "test-engine": { + engine, + maxRecords: 1, + } + }); + // We haven't advanced the timestamp, so we should not validate again. + deepEqual(doctor._getEnginesToValidate([engine]), {}); + // Advance our clock by 11 seconds. + now += 11; + // We should validate again. + deepEqual(doctor._getEnginesToValidate([engine]), { + "test-engine": { + engine, + maxRecords: 1, + } + }); +}); + add_task(async function test_repairs_start() { let repairStarted = false; let problems = {