Bug 1003250 - Disable automatic sync for TPS tests. r=rnewman, a=testonly DONTBUILD
authorHenrik Skupin <mail@hskupin.info>
Mon, 05 May 2014 23:07:52 +0200
changeset 192221 68d24bc3a93d
parent 192220 da8b1c15e2b1
child 192222 04c5fcc3831b
push id3530
push userhskupin@mozilla.com
push date2014-05-08 08:50 +0000
Treeherderresults
reviewersrnewman, testonly
bugs1003250
milestone30.0
Bug 1003250 - Disable automatic sync for TPS tests. r=rnewman, a=testonly 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
@@ -101,26 +101,28 @@ let TPS = {
   _phaselist: {},
   _setupComplete: false,
   _syncActive: false,
   _syncErrors: 0,
   _syncWipeAction: null,
   _tabsAdded: 0,
   _tabsFinished: 0,
   _test: null,
+  _triggeredSync: false,
   _usSinceEpoch: 0,
-  _waitingForSync: false,
 
   _init: function TPS__init() {
     // Check if Firefox Accounts is enabled
     let service = Cc["@mozilla.org/weave/service;1"]
                   .getService(Components.interfaces.nsISupports)
                   .wrappedJSObject;
     this.fxaccounts_enabled = service.fxAccountsEnabled;
 
+    this.delayAutoSync();
+
     OBSERVER_TOPICS.forEach(function (aTopic) {
       Services.obs.addObserver(this, aTopic, true);
     }, this);
 
     // Import the appropriate authentication module
     if (this.fxaccounts_enabled) {
       Cu.import("resource://tps/auth/fxaccounts.jsm", module);
     }
@@ -175,45 +177,53 @@ let TPS = {
             this._syncWipeAction = null;
           }
 
           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.delayAutoSync();
+
+          // If this is the first sync error, retry...
+          if (this._syncErrors === 0) {
+            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");
+          else {
+            this._triggeredSync = false;
+            this.DumpError("Sync error; aborting test");
             return;
           }
+
           break;
 
         case "weave:service:sync:finish":
           this._syncActive = false;
           this._syncErrors = 0;
+          this._triggeredSync = false;
 
-          if (this._waitingForSync) {
-            this._waitingForSync = false;
-            // Wait a second before continuing, otherwise we can get
-            // 'sync not complete' errors.
-            Utils.namedTimer(function() {
-              this.FinishAsyncOperation();
-            }, 1000, this, "postsync");
-          }
+          this.delayAutoSync();
+
+          // 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":
+          // Ensure that the sync operation has been started by TPS
+          if (!this._triggeredSync) {
+            this.DumpError("Automatic sync got triggered, which is not allowed.")
+          }
+
           this._syncActive = true;
           break;
 
         case "weave:engine:start-tracking":
           this._isTracking = true;
           break;
 
         case "weave:engine:stop-tracking":
@@ -222,16 +232,29 @@ let TPS = {
       }
     }
     catch (e) {
       this.DumpError("Exception caught: " + Utils.exceptionStr(e));
       return;
     }
   },
 
+  /**
+   * Given that we cannot complely disable the automatic sync operations, we
+   * massively delay the next sync. Sync operations have to only happen when
+   * directly called via TPS.Sync()!
+   */
+  delayAutoSync: function TPS_delayAutoSync() {
+    Weave.Svc.Prefs.set("scheduler.eolInterval", 7200);
+    Weave.Svc.Prefs.set("scheduler.immediateInterval", 7200);
+    Weave.Svc.Prefs.set("scheduler.idleInterval", 7200);
+    Weave.Svc.Prefs.set("scheduler.activeInterval", 7200);
+    Weave.Svc.Prefs.set("syncThreshold", 10000000);
+  },
+
   StartAsyncOperation: function TPS__StartAsyncOperation() {
     this._operations_pending++;
   },
 
   FinishAsyncOperation: function TPS__FinishAsyncOperation() {
     this._operations_pending--;
     if (!this.operations_pending) {
       this._currentAction++;
@@ -860,17 +883,17 @@ let TPS = {
       Weave.Svc.Prefs.set("firstSync", wipeAction);
     }
     else {
       Weave.Svc.Prefs.reset("firstSync");
     }
 
     this.Login(false);
 
-    this._waitingForSync = true;
+    this._triggeredSync = true;
     this.StartAsyncOperation();
     Weave.Service.sync();
   },
 
   WipeServer: function TPS__WipeServer() {
     Logger.logInfo("Wiping data from server.");
 
     this.Login(false);