Bug 584170 - Make test_service_cluster.js less prone to timing problems [r=mconnor]
--- 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];