Bug 1348743 - avoid running a bookmark validation on every sync. r?tcsc draft
authorMark Hammond <mhammond@skippinet.com.au>
Mon, 20 Mar 2017 19:13:42 +1100
changeset 501762 487799738909c850a8a913df1309b583ab53b149
parent 501295 1b9293be51637f841275541d8991314ca56561a5
child 550000 26b10cd4b122127b5c32ef0fe3a6fecb29c37327
push id50116
push userbmo:markh@mozilla.com
push dateMon, 20 Mar 2017 23:17:38 +0000
reviewerstcsc
bugs1348743
milestone55.0a1
Bug 1348743 - avoid running a bookmark validation on every sync. r?tcsc MozReview-Commit-ID: 49sWR56kfrj
services/sync/modules/doctor.js
services/sync/tests/unit/test_doctor.js
--- a/services/sync/modules/doctor.js
+++ b/services/sync/modules/doctor.js
@@ -101,17 +101,17 @@ this.Doctor = {
 
       if (nowSeconds - lastValidation < validationInterval) {
         log.info(`Skipping validation of ${e.name}: too recent since last validation attempt`);
         continue;
       }
       // 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;
       if (validationProbability < Math.random()) {
         log.info(`Skipping validation of ${e.name}: Probability threshold not met`);
         continue;
       }
 
--- a/services/sync/tests/unit/test_doctor.js
+++ b/services/sync/tests/unit/test_doctor.js
@@ -1,20 +1,67 @@
 /* Any copyright is dedicated to the Public Domain.
    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");
 
 function mockDoctor(mocks) {
   // Clone the object and put mocks in that.
   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(engine) {
+          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 = {
     missingChildren: ["a", "b", "c"],
   }
   let validator = {
     validate(engine) {
       return problems;