Bug 781952 - Part 3: Remove unused Service._updateCluster; r=rnewman
authorGregory Szorc <gps@mozilla.com>
Tue, 14 Aug 2012 11:34:28 -0700
changeset 102215 4a0f07b83709a3dded10fe7e0eecc070551411e7
parent 102214 172d339df58589cb94c456586de9ff5ae72a8c4f
child 102411 a8db42aa1b2820c73aade9acc4de9909562a2a03
push id621
push usergszorc@mozilla.com
push dateWed, 15 Aug 2012 02:10:17 +0000
treeherderservices-central@4a0f07b83709 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs781952
milestone17.0a1
Bug 781952 - Part 3: Remove unused Service._updateCluster; r=rnewman
services/sync/modules/service.js
services/sync/tests/unit/test_service_cluster.js
--- a/services/sync/modules/service.js
+++ b/services/sync/modules/service.js
@@ -421,28 +421,16 @@ WeaveSvc.prototype = {
       // The enabled status being changed back to what it was before.
       Svc.Prefs.reset("engineStatusChanged." + engine);
     } else {
       // Remember that the engine status changed locally until the next sync.
       Svc.Prefs.set("engineStatusChanged." + engine, true);
     }
   },
 
-  // Update cluster if required.
-  // Returns false if the update was not required.
-  _updateCluster: function _updateCluster() {
-    this._log.info("Updating cluster.");
-    let cTime = Date.now();
-    let lastUp = parseFloat(Svc.Prefs.get("lastClusterUpdate"));
-    if (!lastUp || ((cTime - lastUp) >= CLUSTER_BACKOFF)) {
-      return this._clusterManager.setCluster();
-    }
-    return false;
-  },
-
   /**
    * Perform the info fetch as part of a login or key fetch.
    */
   _fetchInfo: function _fetchInfo(url) {
     let infoURL = url || this.infoURL;
 
     this._log.trace("In _fetchInfo: " + infoURL);
     let info;
--- a/services/sync/tests/unit/test_service_cluster.js
+++ b/services/sync/tests/unit/test_service_cluster.js
@@ -1,22 +1,25 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
 Cu.import("resource://services-sync/service.js");
 Cu.import("resource://services-sync/util.js");
 
 function do_check_throws(func) {
   var raised = false;
   try {
     func();
   } catch (ex) {
     raised = true;
   }
   do_check_true(raised);
 }
 
-function test_findCluster() {
+add_test(function test_findCluster() {
   _("Test Service._findCluster()");
   let server;
   try {
     Service.serverURL = TEST_SERVER_URL;
     Identity.account = "johndoe";
 
     _("_findCluster() throws on network errors (e.g. connection refused).");
     do_check_throws(function() {
@@ -55,23 +58,22 @@ function test_findCluster() {
     Identity.account = "joedoe";
     do_check_throws(function() {
       Service._clusterManager._findCluster();
     });
 
   } finally {
     Svc.Prefs.resetBranch("");
     if (server) {
-      server.stop(runNextTest);
+      server.stop(run_next_test);
     }
   }
-}
+});
 
-
-function test_setCluster() {
+add_test(function test_setCluster() {
   _("Test Service._setCluster()");
   let server = httpd_setup({
     "/user/1.0/johndoe/node/weave": httpd_handler(200, "OK", "http://weave.user.node/"),
     "/user/1.0/jimdoe/node/weave": httpd_handler(200, "OK", "null")
   });
   try {
     Service.serverURL = TEST_SERVER_URL;
     Identity.account = "johndoe";
@@ -89,68 +91,16 @@ function test_setCluster() {
 
     _("A 'null' response won't make a difference either.");
     Identity.account = "jimdoe";
     do_check_false(Service._clusterManager.setCluster());
     do_check_eq(Service.clusterURL, "http://weave.user.node/");
 
   } finally {
     Svc.Prefs.resetBranch("");
-    server.stop(runNextTest);
+    server.stop(run_next_test);
   }
-}
-
-function test_updateCluster() {
-  _("Test Service._updateCluster()");
-  let server = httpd_setup({
-    "/user/1.0/johndoe/node/weave": httpd_handler(200, "OK", "http://weave.user.node/"),
-    "/user/1.0/janedoe/node/weave": httpd_handler(200, "OK", "http://weave.cluster.url/")
-  });
-  try {
-    Service.serverURL = TEST_SERVER_URL;
-    Identity.account = "johndoe";
-
-    _("Check initial state.");
-    do_check_eq(Service.clusterURL, "");
-    do_check_eq(Svc.Prefs.get("lastClusterUpdate"), null);
-
-    _("Set the cluster URL.");
-    let before = Date.now();
-    do_check_true(Service._updateCluster());
-    do_check_eq(Service.clusterURL, "http://weave.user.node/");
-    let lastUpdate = parseFloat(Svc.Prefs.get("lastClusterUpdate"));
-    do_check_true(lastUpdate >= before);
-
-    _("Trying to update the cluster URL within the backoff timeout won't do anything.");
-    do_check_false(Service._updateCluster());
-    do_check_eq(Service.clusterURL, "http://weave.user.node/");
-    do_check_eq(parseFloat(Svc.Prefs.get("lastClusterUpdate")), lastUpdate);
-
-    _("Time travel 30 mins into the past and the update will work.");
-    Identity.account = "janedoe";
-    Svc.Prefs.set("lastClusterUpdate", (lastUpdate - 30*60*1000).toString());
-
-    before = Date.now();
-    do_check_true(Service._updateCluster());
-    do_check_eq(Service.clusterURL, "http://weave.cluster.url/");
-    lastUpdate = parseFloat(Svc.Prefs.get("lastClusterUpdate"));
-    do_check_true(lastUpdate >= before);
-  
-  } finally {
-    Svc.Prefs.resetBranch("");
-    server.stop(runNextTest);
-  }
-}
-
-let tests = [test_findCluster, test_setCluster, test_updateCluster];
+});
 
 function run_test() {
-  do_test_pending();
-  runNextTest();
+  initTestLogging();
+  run_next_test();
 }
-
-function runNextTest() {
-  if (tests.length)
-    tests.pop()();
-  else
-    do_test_finished();
-}
-