Bug 1121117 - Add fuzz time to workaround non-monotonicity of Date(). r=keeler, a=test-only
authorCykesiopka <cykesiopka.bmo@gmail.com>
Tue, 03 Mar 2015 14:25:00 +0100
changeset 252085 8358c6c2c417
parent 252084 0725e4cfa3c3
child 252086 72912a71fb98
push id698
push userjlund@mozilla.com
push date2015-03-23 22:08 +0000
treeherdermozilla-release@b0c0ae7b02a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskeeler, test-only
bugs1121117
milestone37.0
Bug 1121117 - Add fuzz time to workaround non-monotonicity of Date(). r=keeler, a=test-only
security/manager/ssl/tests/unit/test_ocsp_timeout.js
--- a/security/manager/ssl/tests/unit/test_ocsp_timeout.js
+++ b/security/manager/ssl/tests/unit/test_ocsp_timeout.js
@@ -16,17 +16,17 @@
 // Otherwise, they will succeed.
 
 let gSocketListener = {
   onSocketAccepted: function(serverSocket, socketTransport) {
     socketTransport.setTimeout(Ci.nsISocketTransport.TIMEOUT_CONNECT, 30);
     socketTransport.setTimeout(Ci.nsISocketTransport.TIMEOUT_READ_WRITE, 30);
   },
 
-  onStopListening: function(serverSocket, socketTransport) {}
+  onStopListening: function(serverSocket, status) {}
 };
 
 function run_test() {
   do_get_profile();
 
   add_tls_server_setup("OCSPStaplingServer");
 
   let socket = Cc["@mozilla.org/network/server-socket;1"]
@@ -51,24 +51,34 @@ function add_tests_in_mode(useHardFail) 
 
   add_connection_test("ocsp-stapling-none.example.com", useHardFail
                       ? getXPCOMStatusFromNSS(SEC_ERROR_OCSP_SERVER_ERROR)
                       : Cr.NS_OK, clearSessionCache);
 
   // Reset state
   add_test(function() {
     let endTime = new Date();
+    let timeDifference = endTime - startTime;
+    do_print(`useHardFail = ${useHardFail}`);
+    do_print(`startTime = ${startTime.getTime()} (${startTime})`);
+    do_print(`endTime = ${endTime.getTime()} (${endTime})`);
+    do_print(`timeDifference = ${timeDifference}ms`);
+
     // With OCSP hard-fail on, we timeout after 10 seconds.
     // With OCSP soft-fail, we timeout after 2 seconds.
+    // Date() is not guaranteed to be monotonic, so add extra fuzz time to
+    // prevent intermittent failures (this only appeared to be a problem on
+    // Windows XP). See Bug 1121117.
+    const FUZZ_MS = 300;
     if (useHardFail) {
-      do_check_true((endTime - startTime) > 10000);
+      do_check_true(timeDifference + FUZZ_MS > 10000);
     } else {
-      do_check_true((endTime - startTime) > 2000);
+      do_check_true(timeDifference + FUZZ_MS > 2000);
     }
     // Make sure we didn't wait too long.
     // (Unfortunately, we probably can't have a tight upper bound on
     // how long is too long for this test, because we might be running
     // on slow hardware.)
-    do_check_true((endTime - startTime) < 60000);
+    do_check_true(timeDifference < 60000);
     clearOCSPCache();
     run_next_test();
   });
 }