Bug 986190 - [tps] Synced data on the server is not always wiped at the end of a test. r=jgriffin, r=rnewman a=lsblakk DONTBUILD
authorHenrik Skupin <mail@hskupin.info>
Wed, 02 Apr 2014 22:58:14 +0200
changeset 191555 2356542e1b84a53f0835926011a13d5eb9d77c16
parent 191554 5d9d8d961c4a4751928bb7bc52678497d4525484
child 191556 018483c2e162f13efe7428eb311931e2f708b7d6
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgriffin, rnewman, lsblakk
bugs986190
milestone30.0a2
Bug 986190 - [tps] Synced data on the server is not always wiped at the end of a test. r=jgriffin, r=rnewman a=lsblakk 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() {
@@ -102,17 +109,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]),
 
@@ -120,58 +127,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;
     }
   },
 
@@ -185,20 +216,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:
@@ -495,17 +522,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);