Bug 986190 - [tps] Synced data on the server is not always wiped at the end of a test. r=jgriffin, r=rnewman DONTBUILD
authorHenrik Skupin <mail@hskupin.info>
Wed, 02 Apr 2014 22:58:14 +0200
changeset 195308 d82714afadf14a0dd5d319609810598cf247d2f4
parent 195307 fa89a5d387002722e8eb0242c0fd348d657c8c49
child 195309 3ba8c4d4769814d2c19bc0a4fb08aef72ce4c06b
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgriffin, rnewman
bugs986190
milestone31.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 986190 - [tps] Synced data on the server is not always wiped at the end of a test. r=jgriffin, r=rnewman DONTBUILD
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
@@ -62,33 +62,40 @@ const SYNC_WIPE_CLIENT  = "wipe-client";
 const SYNC_WIPE_REMOTE  = "wipe-remote";
 const SYNC_WIPE_SERVER  = "wipe-server";
 const SYNC_RESET_CLIENT = "reset-client";
 const SYNC_START_OVER   = "start-over";
 
 const OBSERVER_TOPICS = ["fxaccounts:onlogin",
                          "fxaccounts:onlogout",
                          "private-browsing",
+                         "quit-application-requested",
                          "sessionstore-windows-restored",
                          "weave:engine:start-tracking",
                          "weave:engine:stop-tracking",
+                         "weave:service:login:error",
                          "weave:service:setup-complete",
                          "weave:service:sync:finish",
+                         "weave:service:sync:delayed",
                          "weave:service:sync:error",
+                         "weave:service:sync:start"
                         ];
 
 let TPS = {
   _currentAction: -1,
   _currentPhase: -1,
   _enabledEngines: null,
   _errors: 0,
+  _finalPhase: false,
   _isTracking: false,
   _operations_pending: 0,
+  _phaseFinished: false,
   _phaselist: {},
   _setupComplete: false,
+  _syncActive: false,
   _syncErrors: 0,
   _tabsAdded: 0,
   _tabsFinished: 0,
   _test: null,
   _usSinceEpoch: 0,
   _waitingForSync: false,
 
   _init: function TPS__init() {
@@ -106,17 +113,17 @@ let TPS = {
     if (this.fxaccounts_enabled) {
       Cu.import("resource://tps/auth/fxaccounts.jsm", module);
     }
     else {
       Cu.import("resource://tps/auth/sync.jsm", module);
     }
   },
 
-  DumpError: function (msg) {
+  DumpError: function TPS__DumpError(msg) {
     this._errors++;
     Logger.logError("[phase" + this._currentPhase + "] " + msg);
     this.quit();
   },
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
                                          Ci.nsISupportsWeakReference]),
 
@@ -124,58 +131,82 @@ let TPS = {
     try {
       Logger.logInfo("----------event observed: " + topic);
 
       switch(topic) {
         case "private-browsing":
           Logger.logInfo("private browsing " + data);
           break;
 
+        case "quit-application-requested":
+          // Ensure that we eventually wipe the data on the server
+          if (this._errors || !this._phaseFinished || this._finalPhase) {
+            try {
+              this.WipeServer();
+            } catch (ex) {}
+          }
+
+          OBSERVER_TOPICS.forEach(function(topic) {
+            Services.obs.removeObserver(this, topic);
+          }, this);
+
+          Logger.close();
+
+          break;
+
+        case "sessionstore-windows-restored":
+          Utils.nextTick(this.RunNextTestAction, this);
+          break;
+
+        case "weave:service:setup-complete":
+          this._setupComplete = true;
+          break;
+
         case "weave:service:sync:error":
+          this._syncActive = false;
+
           if (this._waitingForSync && this._syncErrors == 0) {
             // if this is the first sync error, retry...
             Logger.logInfo("sync error; retrying...");
             this._syncErrors++;
             this._waitingForSync = false;
             Utils.nextTick(this.RunNextTestAction, this);
           }
           else if (this._waitingForSync) {
             // ...otherwise abort the test
             this.DumpError("sync error; aborting test");
             return;
           }
           break;
 
-        case "weave:service:setup-complete":
-          this._setupComplete = true;
-          break;
+        case "weave:service:sync:finish":
+          this._syncActive = false;
+          this._syncErrors = 0;
 
-        case "weave:service:sync:finish":
           if (this._waitingForSync) {
-            this._syncErrors = 0;
             this._waitingForSync = false;
             // Wait a second before continuing, otherwise we can get
             // 'sync not complete' errors.
             Utils.namedTimer(function() {
               this.FinishAsyncOperation();
             }, 1000, this, "postsync");
           }
           break;
 
+        case "weave:service:sync:start":
+          this._syncActive = true;
+          break;
+
         case "weave:engine:start-tracking":
           this._isTracking = true;
           break;
 
         case "weave:engine:stop-tracking":
           this._isTracking = false;
           break;
-
-        case "sessionstore-windows-restored":
-          Utils.nextTick(this.RunNextTestAction, this);
-          break;
       }
     }
     catch (e) {
       this.DumpError("Exception caught: " + Utils.exceptionStr(e));
       return;
     }
   },
 
@@ -189,20 +220,16 @@ let TPS = {
       this._currentAction++;
       Utils.nextTick(function() {
         this.RunNextTestAction();
       }, this);
     }
   },
 
   quit: function TPS__quit() {
-    OBSERVER_TOPICS.forEach(function(topic) {
-      Services.obs.removeObserver(this, topic);
-    }, this);
-    Logger.close();
     this.goQuitApplication();
   },
 
   HandleWindows: function (aWindow, action) {
     Logger.logInfo("executing action " + action.toUpperCase() +
                    " on window " + JSON.stringify(aWindow));
     switch(action) {
       case ACTION_ADD:
@@ -499,17 +526,18 @@ let TPS = {
   },
 
   RunNextTestAction: function() {
     try {
       if (this._currentAction >=
           this._phaselist["phase" + this._currentPhase].length) {
         // we're all done
         Logger.logInfo("test phase " + this._currentPhase + ": " +
-          (this._errors ? "FAIL" : "PASS"));
+                       (this._errors ? "FAIL" : "PASS"));
+        this._phaseFinished = true;
         this.quit();
         return;
       }
 
       if (this.seconds_since_epoch)
         this._usSinceEpoch = this.seconds_since_epoch * 1000 * 1000;
       else {
         this.DumpError("seconds-since-epoch not set");
@@ -633,24 +661,24 @@ let TPS = {
 
       Logger.logInfo("setting client.name to " + this.phases["phase" + this._currentPhase]);
       Weave.Svc.Prefs.set("client.name", this.phases["phase" + this._currentPhase]);
 
       // TODO Phases should be defined in a data type that has strong
       // ordering, not by lexical sorting.
       let currentPhase = parseInt(this._currentPhase, 10);
 
-      // Reset everything at the beginning of the test.
+      // Login at the beginning of the test.
       if (currentPhase <= 1) {
-        this_phase.unshift([this.ResetData]);
+        this_phase.unshift([this.Login]);
       }
 
       // Wipe the server at the end of the final test phase.
       if (currentPhase >= Object.keys(this.phases).length) {
-        this_phase.push([this.WipeServer]);
+        this._finalPhase = true;
       }
 
       // If a custom server was specified, set it now
       if (this.config["serverURL"]) {
         Weave.Service.serverURL = this.config.serverURL;
         prefs.setCharPref('tps.serverURL', this.config.serverURL);
       }
 
@@ -755,57 +783,34 @@ let TPS = {
 
   /**
    * Waits for Sync to logged in before returning
    */
   waitForSetupComplete: function waitForSetup() {
     if (!this._setupComplete) {
       this.waitForEvent("weave:service:setup-complete");
     }
+  },
 
-    let cb = Async.makeSyncCallback();
-    Utils.nextTick(cb);
-    Async.waitForSyncCallback(cb);
+  /**
+   * Waits for Sync to be finished before returning
+   */
+  waitForSyncFinished: function TPS__waitForSyncFinished() {
+    if (this._syncActive) {
+      this.waitForEvent("weave:service:sync:finished");
+    }
   },
 
   /**
    * Waits for Sync to start tracking before returning.
    */
   waitForTracking: function waitForTracking() {
     if (!this._isTracking) {
       this.waitForEvent("weave:engine:start-tracking");
     }
-
-    let cb = Async.makeSyncCallback();
-    Utils.nextTick(cb);
-    Async.waitForSyncCallback(cb);
-  },
-
-  /**
-   * Reset the client and server to an empty/pure state.
-   *
-   * All data on the server is wiped and replaced with new keys and local
-   * client data. The local client is configured such that it is in sync
-   * with the server and ready to handle changes.
-   *
-   * This is typically called at the beginning of every test to set up a clean
-   * slate.
-   *
-   * This executes synchronously and doesn't return until things are in a good
-   * state.
-   */
-  ResetData: function ResetData() {
-    this.Login(true);
-
-    Weave.Service.login();
-    Weave.Service.wipeServer();
-    Weave.Service.resetClient();
-    Weave.Service.login();
-
-    this.waitForTracking();
   },
 
   /**
    * Login on the server
    */
   Login: function Login(force) {
     if (Authentication.isLoggedIn && !force) {
       return;
@@ -843,18 +848,20 @@ let TPS = {
 
     this._waitingForSync = true;
     this.StartAsyncOperation();
 
     Weave.Service.sync();
   },
 
   WipeServer: function TPS__WipeServer() {
-    Logger.logInfo("WipeServer()");
-    this.Login();
+    Logger.logInfo("Wiping data from server.");
+
+    this.Login(false);
+    Weave.Service.login();
     Weave.Service.wipeServer();
   },
 
   /**
    * Action which ensures changes are being tracked before returning.
    */
   EnsureTracking: function EnsureTracking() {
     this.Login(false);