Bug 1306466 - Add timers resolution skew to History future date check, to avoid intermittent failures. r=adw
authorMarco Bonardo <mbonardo@mozilla.com>
Fri, 30 Sep 2016 11:42:28 +0200
changeset 316132 43c03bc692083131117463df747c15ab82eb3ad7
parent 316131 3820efc791553122908ff5b2f209d90bc305b527
child 316133 f2181015902f1bd9e533bf6103bbbb9e65d2436e
push id30762
push userphilringnalda@gmail.com
push dateSat, 01 Oct 2016 21:00:36 +0000
treeherdermozilla-central@d1fd56faaeb9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw
bugs1306466
milestone52.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 1306466 - Add timers resolution skew to History future date check, to avoid intermittent failures. r=adw MozReview-Commit-ID: CI4rakbklhq
toolkit/components/places/History.jsm
toolkit/components/places/tests/history/test_insert.js
--- a/toolkit/components/places/History.jsm
+++ b/toolkit/components/places/History.jsm
@@ -85,16 +85,19 @@ Cu.importGlobalProperties(["URL"]);
  * Whenever we update or remove numerous pages, it is preferable
  * to yield time to the main thread every so often to avoid janking.
  * These constants determine the maximal number of notifications we
  * may emit before we yield.
  */
 const NOTIFICATION_CHUNK_SIZE = 300;
 const ONRESULT_CHUNK_SIZE = 300;
 
+// Timers resolution is not always good, it can have a 16ms precision on Win.
+const TIMERS_RESOLUTION_SKEW_MS = 16;
+
 /**
  * Sends a bookmarks notification through the given observers.
  *
  * @param observers
  *        array of nsINavBookmarkObserver objects.
  * @param notification
  *        the notification name.
  * @param args
@@ -495,17 +498,17 @@ function validatePageInfo(pageInfo) {
     };
 
     if (!isValidTransitionType(visit.transition)) {
       throw new TypeError(`transition: ${visit.transition} is not a valid transition type`);
     }
 
     if (inVisit.date) {
       ensureDate(inVisit.date);
-      if (inVisit.date > Date.now()) {
+      if (inVisit.date > (Date.now() + TIMERS_RESOLUTION_SKEW_MS)) {
         throw new TypeError(`date: ${inVisit.date} cannot be a future date`);
       }
       visit.date = inVisit.date;
     }
 
     if (inVisit.referrer) {
       visit.referrer = normalizeToURLOrGUID(inVisit.referrer);
     }
--- a/toolkit/components/places/tests/history/test_insert.js
+++ b/toolkit/components/places/tests/history/test_insert.js
@@ -73,17 +73,17 @@ add_task(function* test_insert_error_cas
           transition: TRANSITION_LINK,
           date: "a"
         }
       ]}),
     /TypeError: Expected a Date, got a/,
     "passing a second visit object with an invalid date to History.insert should throw a TypeError"
   );
   let futureDate = new Date();
-  futureDate.setDate(futureDate.getDate() + 1);
+  futureDate.setDate(futureDate.getDate() + 1000);
   Assert.throws(
     () =>  PlacesUtils.history.insert({
       url: TEST_URL,
       visits: [
         {
           transition: TRANSITION_LINK,
           date: futureDate,
         }