Bug 584170 - Make test_service_cluster.js less prone to timing problems [r=mconnor]

This commit is contained in:
Philipp von Weitershausen 2010-08-03 22:20:40 +02:00
parent c745f15b21
commit d3c2e2f9f5

View File

@ -120,24 +120,26 @@ function test_updateCluster() {
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("");