Bug 1383773 - Fix race between browser and TPS initialization. r=markh
authorThom Chiovoloni <tchiovoloni@mozilla.com>
Mon, 24 Jul 2017 11:10:32 -0400
changeset 419542 5105e408029e772a9d18b39e25aec655a9e52cb4
parent 419541 ca6f811e807ea7c4a2296de5838d4fa61b566d14
child 419543 1eaacee91b1b9d993d22385c919991eeeda08d5c
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh
bugs1383773
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1383773 - Fix race between browser and TPS initialization. r=markh MozReview-Commit-ID: 7Ie1IzRzEbI
services/sync/tps/extensions/tps/resource/tps.jsm
--- a/services/sync/tps/extensions/tps/resource/tps.jsm
+++ b/services/sync/tps/extensions/tps/resource/tps.jsm
@@ -16,16 +16,17 @@ var module = this;
 // Global modules
 Cu.import("resource://gre/modules/Log.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/AppConstants.jsm");
 Cu.import("resource://gre/modules/PlacesUtils.jsm");
 Cu.import("resource://gre/modules/FileUtils.jsm");
 Cu.import("resource://gre/modules/Timer.jsm");
+Cu.import("resource://gre/modules/PromiseUtils.jsm");
 Cu.import("resource://services-common/async.js");
 Cu.import("resource://services-sync/constants.js");
 Cu.import("resource://services-sync/main.js");
 Cu.import("resource://services-sync/util.js");
 Cu.import("resource://services-sync/telemetry.js");
 Cu.import("resource://services-sync/bookmark_validator.js");
 Cu.import("resource://services-sync/engines/passwords.js");
 Cu.import("resource://services-sync/engines/forms.js");
@@ -124,16 +125,17 @@ var TPS = {
   _test: null,
   _triggeredSync: false,
   _usSinceEpoch: 0,
   _requestedQuit: false,
   shouldValidateAddons: false,
   shouldValidateBookmarks: false,
   shouldValidatePasswords: false,
   shouldValidateForms: false,
+  _windowsUpDeferred: PromiseUtils.defer(),
 
   _init: function TPS__init() {
     this.delayAutoSync();
 
     OBSERVER_TOPICS.forEach(function(aTopic) {
       Services.obs.addObserver(this, aTopic, true);
     }, this);
 
@@ -171,24 +173,17 @@ var TPS = {
             Services.obs.removeObserver(this, topic);
           }, this);
 
           Logger.close();
 
           break;
 
         case "sessionstore-windows-restored":
-          // This is a terrible hack, but fixes cases where tps (usually cleanup)
-          // fails because of sessionstore restoring windows before tps is able
-          // to initialize. This used to take only 1 tick, but at some point
-          // session store started restoring windows sooner, or tps started
-          // initializing later.
-          setTimeout(() => {
-            this.RunNextTestAction();
-          }, 1000);
+          this._windowsUpDeferred.resolve();
           break;
 
         case "weave:service:setup-complete":
           this._setupComplete = true;
 
           if (this._syncWipeAction) {
             Weave.Svc.Prefs.set("firstSync", this._syncWipeAction);
             this._syncWipeAction = null;
@@ -942,16 +937,19 @@ var TPS = {
 
       Logger.logInfo("setting client.name to " + this.phases[this._currentPhase]);
       Weave.Svc.Prefs.set("client.name", this.phases[this._currentPhase]);
 
       this._interceptSyncTelemetry();
 
       // start processing the test actions
       this._currentAction = 0;
+      this._windowsUpDeferred.promise.then(() => {
+        this.RunNextTestAction();
+      });
     } catch (e) {
       this.DumpError("_executeTestPhase failed", e);
     }
   },
 
   /**
    * Override sync telemetry functions so that we can detect errors generating
    * the sync ping, and count how many pings we report.