Bug 1335752 - Remove all observers when finalizing the tracker. r=markh
MozReview-Commit-ID: CKc19VAO9WW
--- 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();