Bug 1306466 - Add timers resolution skew to History future date check, to avoid intermittent failures. r=adw draft
authorMarco Bonardo <mbonardo@mozilla.com>
Fri, 30 Sep 2016 11:42:28 +0200
changeset 419416 6c2ec323d836a00efb48133a5e30186ea475f30e
parent 418992 f7d5008ee2ab9200052e45ad6ecc3f3a348f7f86
child 532577 9dcc715560c35b50cc0ebfe0938d62626370ad47
push id30934
push usermak77@bonardo.net
push dateFri, 30 Sep 2016 10:07:26 +0000
reviewersadw
bugs1306466
milestone52.0a1
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,
         }