Bug 1439061 - Stop tracking on engine finalization and clean up in history engine test. r?tcsc draft
authorKit Cambridge <kit@yakshaving.ninja>
Fri, 16 Feb 2018 19:21:06 -0800
changeset 756636 6774ffd81b736bbd69b1e689a6756e7852d8cde6
parent 753128 aac7218d86242042f836d6258ff46dc7e4d62df2
push id99510
push userbmo:kit@mozilla.com
push dateSat, 17 Feb 2018 03:46:43 +0000
reviewerstcsc
bugs1439061
milestone60.0a1
Bug 1439061 - Stop tracking on engine finalization and clean up in history engine test. r?tcsc MozReview-Commit-ID: JjgMdQwbnly
services/sync/modules/engines.js
services/sync/tests/unit/test_history_engine.js
--- a/services/sync/modules/engines.js
+++ b/services/sync/modules/engines.js
@@ -242,16 +242,17 @@ Tracker.prototype = {
       await this.stop();
       await this.clearChangedIDs();
     }
   },
 
   async finalize() {
     // Persist all pending tracked changes to disk, and wait for the final write
     // to finish.
+    await this.stop();
     this._saveChangedIDs();
     await this._storage.finalize();
   },
 };
 
 
 
 /**
--- a/services/sync/tests/unit/test_history_engine.js
+++ b/services/sync/tests/unit/test_history_engine.js
@@ -123,17 +123,19 @@ add_task(async function test_history_dow
     ["place0000005", "place0000006", "place0000007", "place0000008", "place0000009"]);
 
   // Sync again to clear out the backlog.
   engine.lastModified = collection.modified;
   ping = await sync_engine_and_validate_telem(engine, false);
   deepEqual(ping.engines[0].incoming, { applied: 5 });
 
   deepEqual(Array.from(engine.toFetch), []);
-  await PlacesUtils.history.clear();
+
+  await engine.wipeClient();
+  await engine.finalize();
 });
 
 add_task(async function test_history_visit_roundtrip() {
   let engine = new HistoryEngine(Service);
   await engine.initialize();
   let server = await serverForFoo(engine);
   await SyncTestingInfrastructure(server);
 
@@ -178,41 +180,46 @@ add_task(async function test_history_vis
   engine.lastSync = Date.now() / 1000 - 30;
   await sync_engine_and_validate_telem(engine, false);
 
   // Make sure that we didn't duplicate the visit when inserting. (Prior to bug
   // 1423395, we would insert a duplicate visit, where the timestamp was
   // effectively `Math.round(microsecondTimestamp / 1000) * 1000`.)
   visits = await PlacesSyncUtils.history.fetchVisitsForURL("https://www.example.com");
   equal(visits.length, 2);
-  await PlacesUtils.history.clear();
+
+  await engine.wipeClient();
+  await engine.finalize();
 });
 
 add_task(async function test_history_visit_dedupe_old() {
   let engine = new HistoryEngine(Service);
   await engine.initialize();
   let server = await serverForFoo(engine);
   await SyncTestingInfrastructure(server);
 
-  engine._tracker.start();
-
+  let initialVisits = Array.from({ length: 25 }, (_, index) => ({
+    transition: PlacesUtils.history.TRANSITION_LINK,
+    date: new Date(Date.UTC(2017, 10, 1 + index)),
+  }));
+  initialVisits.push({
+    transition: PlacesUtils.history.TRANSITION_LINK,
+    date: new Date(),
+  });
   await PlacesUtils.history.insert({
     url: "https://www.example.com",
-    visits: Array.from({ length: 25 }, (_, index) => ({
-      transition: PlacesUtils.history.TRANSITION_LINK,
-      date: new Date(Date.UTC(2017, 10, 1 + index)),
-    }))
+    visits: initialVisits,
   });
 
   let recentVisits = await PlacesSyncUtils.history.fetchVisitsForURL("https://www.example.com");
   equal(recentVisits.length, 20);
   let {visits: allVisits, guid} = await PlacesUtils.history.fetch("https://www.example.com", {
     includeVisits: true
   });
-  equal(allVisits.length, 25);
+  equal(allVisits.length, 26);
 
   let collection = server.user("foo").collection("history");
 
   await sync_engine_and_validate_telem(engine, false);
 
   let wbo = collection.wbo(guid);
   let data = JSON.parse(JSON.parse(wbo.payload).ciphertext);
 
@@ -238,15 +245,17 @@ add_task(async function test_history_vis
   collection.insertWBO(new ServerWBO(guid, encryptPayload(data), Date.now() / 1000 + 10));
   engine.lastSync = Date.now() / 1000 - 30;
   await sync_engine_and_validate_telem(engine, false);
 
   allVisits = (await PlacesUtils.history.fetch("https://www.example.com", {
     includeVisits: true
   })).visits;
 
-  equal(allVisits.length, 27);
+  equal(allVisits.length, 28);
   ok(allVisits.find(x => x.date.getTime() === Date.UTC(2017, 11, 4)),
      "Should contain the Dec. 4th visit");
   ok(allVisits.find(x => x.date.getTime() === Date.UTC(2017, 11, 5)),
      "Should contain the Dec. 5th visit");
-  await PlacesUtils.history.clear();
+
+  await engine.wipeClient();
+  await engine.finalize();
 });