Skip to content

Commit

Permalink
Bug 831404 - Don't assume that timers run precisely. r=gps
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Newman committed Mar 26, 2013
1 parent 4cf699a commit b123fd1
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions services/datareporting/tests/xpcshell/test_policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -692,10 +692,16 @@ add_test(function test_polling_implicit_acceptance() {
});

let count = 0;

// Track JS elapsed time, so we can decide if we've waited for enough ticks.
let start;
Object.defineProperty(policy, "checkStateAndTrigger", {
value: function CheckStateAndTriggerProxy() {
count++;
print("checkStateAndTrigger count: " + count);
let now = Date.now();
let delta = now - start;
print("checkStateAndTrigger count: " + count + ", now " + now +
", delta " + delta);

// Account for some slack.
DataReportingPolicy.prototype.checkStateAndTrigger.call(policy);
Expand All @@ -707,24 +713,27 @@ add_test(function test_polling_implicit_acceptance() {
// 3) still ~50ms away from implicit acceptance
// 4) Implicit acceptance recorded. Data submission requested.
// 5) Request still pending. No new submission requested.
//
// Note that, due to the inaccuracy of timers, 4 might not happen until 5
// firings have occurred. Yay. So we watch times, not just counts.

do_check_eq(listener.notifyUserCount, 1);

if (count == 1) {
listener.lastNotifyRequest.onUserNotifyComplete();
}

if (count < 4) {
if (delta <= 750) {
do_check_false(policy.dataSubmissionPolicyAccepted);
do_check_eq(listener.requestDataUploadCount, 0);
} else {
} else if (count > 3) {
do_check_true(policy.dataSubmissionPolicyAccepted);
do_check_eq(policy.dataSubmissionPolicyResponseType,
"accepted-implicit-time-elapsed");
do_check_eq(listener.requestDataUploadCount, 1);
}

if (count > 4) {
if ((count > 4) && policy.dataSubmissionPolicyAccepted) {
do_check_eq(listener.requestDataUploadCount, 1);
policy.stopPolling();
run_next_test();
Expand All @@ -734,6 +743,7 @@ add_test(function test_polling_implicit_acceptance() {

policy.firstRunDate = new Date(Date.now() - 4 * 24 * 60 * 60 * 1000);
policy.nextDataSubmissionDate = new Date(Date.now());
start = Date.now();
policy.startPolling();
});

Expand Down

0 comments on commit b123fd1

Please sign in to comment.