Bug 1335752 - Remove all observers when finalizing the tracker. r=markh draft
authorKit Cambridge <kit@yakshaving.ninja>
Mon, 13 Feb 2017 13:16:30 -0800
changeset 488323 804897e8a18e740483fa96e980ee63a76fa2616a
parent 488125 7abeac2f2d668554f0093fc0bdb1488f9a77d16e
child 488324 7cce5414bf69df77efb86b8f52d1cc2fc0baac6e
child 488771 c01eed08e72fd4ff654b3afed0472cb5185aec4e
push id46495
push userbmo:kit@mozilla.com
push dateThu, 23 Feb 2017 00:53:19 +0000
reviewersmarkh
bugs1335752
milestone54.0a1
Bug 1335752 - Remove all observers when finalizing the tracker. r=markh MozReview-Commit-ID: CKc19VAO9WW
services/sync/modules/engines.js
--- a/services/sync/modules/engines.js
+++ b/services/sync/modules/engines.js
@@ -245,17 +245,30 @@ Tracker.prototype = {
           this._isTracking = false;
         }
         return;
       case "nsPref:changed":
         if (data == PREFS_BRANCH + "engine." + this.engine.prefName) {
           this.onEngineEnabledChanged(this.engine.enabled);
         }
     }
-  }
+  },
+
+  async finalize() {
+    // Stop listening for tracking and engine enabled change notifications.
+    // Important for tests where we unregister the engine during cleanup.
+    Svc.Obs.remove("weave:engine:start-tracking", this);
+    Svc.Obs.remove("weave:engine:stop-tracking", this);
+    Svc.Prefs.ignore("engine." + this.engine.prefName, this);
+
+    // Persist all pending tracked changes to disk, and wait for the final write
+    // to finish.
+    this._saveChangedIDs();
+    await this._storage.finalize();
+  },
 };
 
 
 
 /**
  * The Store serves as the interface between Sync and stored data.
  *
  * The name "store" is slightly a misnomer because it doesn't actually "store"
@@ -728,19 +741,17 @@ Engine.prototype = {
    * must have a `validate(engine)` method that returns a promise to an object
    * with a getSummary method). Otherwise return null.
    */
   getValidator() {
     return null;
   },
 
   finalize() {
-    // Persist all pending tracked changes to disk.
-    this._tracker._saveChangedIDs();
-    Async.promiseSpinningly(this._tracker._storage.finalize());
+    Async.promiseSpinningly(this._tracker.finalize());
   },
 };
 
 this.SyncEngine = function SyncEngine(name, service) {
   Engine.call(this, name || "SyncEngine", service);
 
   this.loadToFetch();
   this.loadPreviousFailed();