Bug 831404 - Add logging to test_policy.js. r=trivial,test-only
authorRichard Newman <rnewman@mozilla.com>
Wed, 30 Jan 2013 20:07:34 -0800
changeset 130307 91db03dc9c5a32968dd5c14a5328a27479f8cc8c
parent 130306 09334ec10eba0682091df627d2da59af4def8451
child 130308 21cbd89537b584c83a16dbfd6ca6c776c013b776
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstrivial, test-only
bugs831404
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 831404 - Add logging to test_policy.js. r=trivial,test-only
services/datareporting/tests/xpcshell/test_policy.js
--- a/services/datareporting/tests/xpcshell/test_policy.js
+++ b/services/datareporting/tests/xpcshell/test_policy.js
@@ -625,41 +625,52 @@ add_test(function test_delete_remote_dat
   do_check_eq(listener.requestDataUploadCount, 1);
   do_check_eq(listener.requestRemoteDeleteCount, 1);
 
   run_next_test();
 });
 
 add_test(function test_polling() {
   let [policy, policyPrefs, hrPrefs, listener] = getPolicy("polling");
+  let intended = 500;
 
   // Ensure checkStateAndTrigger is called at a regular interval.
-  let now = new Date();
+  let then = Date.now();
+  print("Starting run: " + then);
   Object.defineProperty(policy, "POLL_INTERVAL_MSEC", {
-    value: 500,
+    value: intended,
   });
   let count = 0;
 
   Object.defineProperty(policy, "checkStateAndTrigger", {
     value: function fakeCheckStateAndTrigger() {
-      let now2 = new Date();
+      let now = Date.now();
+      let after = now - then;
       count++;
 
-      do_check_true(now2.getTime() - now.getTime() >= 500);
-      now = now2;
+      print("Polled at " + now + " after " + after + "ms, intended " + intended);
+      do_check_true(after >= intended);
       DataReportingPolicy.prototype.checkStateAndTrigger.call(policy);
 
       if (count >= 2) {
         policy.stopPolling();
 
         do_check_eq(listener.notifyUserCount, 0);
         do_check_eq(listener.requestDataUploadCount, 0);
 
         run_next_test();
       }
+
+      // "Specified timer period will be at least the time between when
+      // processing for last firing the callback completes and when the next
+      // firing occurs."
+      //
+      // That means we should set 'then' at the *end* of our handler, not
+      // earlier.
+      then = Date.now();
     }
   });
   policy.startPolling();
 });
 
 // Ensure that implicit acceptance of policy is resolved through polling.
 //
 // This is probably covered by other tests. But, it's best to have explicit