Bug 584170 - Make test_service_cluster.js less prone to timing problems [r=mconnor]
authorPhilipp von Weitershausen <philipp@weitershausen.de>
Tue, 03 Aug 2010 22:20:40 +0200
changeset 49589 d38e493718cbc3b1aab79363fea40d38aaf4ceb9
parent 48779 f4c06a11afca25207f587e1bf2f7dde1cb4b1769
child 49590 3aa713951ac99a97da3a610a9609ea94749860ab
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconnor
bugs584170
Bug 584170 - Make test_service_cluster.js less prone to timing problems [r=mconnor]
services/sync/tests/unit/test_service_cluster.js
--- a/services/sync/tests/unit/test_service_cluster.js
+++ b/services/sync/tests/unit/test_service_cluster.js
@@ -115,34 +115,36 @@ function test_updateCluster() {
     Weave.Service.serverURL = "http://localhost:8080/";
     Weave.Service.username = "johndoe";
 
     _("Check initial state.");
     do_check_eq(Weave.Service.clusterURL, "");
     do_check_eq(Svc.Prefs.get("lastClusterUpdate"), null);
 
     _("Set the cluster URL.");
+    let before = Date.now();
     do_check_true(Weave.Service._updateCluster());
     do_check_eq(Weave.Service.clusterURL, "http://weave.user.node/");
-    let lastUpdate = parseInt(Svc.Prefs.get("lastClusterUpdate"), 10);
-    do_check_true(lastUpdate > Date.now() - 1000);
+    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(Weave.Service._updateCluster());
     do_check_eq(Weave.Service.clusterURL, "http://weave.user.node/");
-    do_check_eq(parseInt(Svc.Prefs.get("lastClusterUpdate"), 10), lastUpdate);
+    do_check_eq(parseFloat(Svc.Prefs.get("lastClusterUpdate")), lastUpdate);
 
     _("Time travel 30 mins into the past and the update will work.");
     Weave.Service.username = "janedoe";
     Svc.Prefs.set("lastClusterUpdate", (lastUpdate - 30*60*1000).toString());
 
+    before = Date.now();
     do_check_true(Weave.Service._updateCluster());
     do_check_eq(Weave.Service.clusterURL, "http://weave.cluster.url/");
-    lastUpdate = parseInt(Svc.Prefs.get("lastClusterUpdate"), 10);
-    do_check_true(lastUpdate > Date.now() - 1000);
+    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];