changeset 8180:3255a4e348a1

8023639: Difference between LocalTime.now(Clock.systemDefaultZone()) and LocalTime.now() executed successively is more than 100 000 000 nanoseconds for slow machines Summary: Test timed out on a slow machine; it is not a conformance test and should be in the test subtree Reviewed-by: darcy, sherman
author rriggs
date Sat, 14 Sep 2013 13:55:04 -0400
parents a7980b099af1
children 35bb1c7f227c
files test/java/time/tck/java/time/TCKLocalTime.java test/java/time/test/java/time/TestLocalTime.java
diffstat 2 files changed, 21 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/time/tck/java/time/TCKLocalTime.java	Fri Sep 06 15:36:00 2013 -0700
+++ b/test/java/time/tck/java/time/TCKLocalTime.java	Sat Sep 14 13:55:04 2013 -0400
@@ -283,17 +283,6 @@
     }
 
     //-----------------------------------------------------------------------
-    // now()
-    //-----------------------------------------------------------------------
-    @Test
-    public void now() {
-        LocalTime expected = LocalTime.now(Clock.systemDefaultZone());
-        LocalTime test = LocalTime.now();
-        long diff = Math.abs(test.toNanoOfDay() - expected.toNanoOfDay());
-        assertTrue(diff < 100000000);  // less than 0.1 secs
-    }
-
-    //-----------------------------------------------------------------------
     // now(ZoneId)
     //-----------------------------------------------------------------------
     @Test(expectedExceptions=NullPointerException.class)
--- a/test/java/time/test/java/time/TestLocalTime.java	Fri Sep 06 15:36:00 2013 -0700
+++ b/test/java/time/test/java/time/TestLocalTime.java	Sat Sep 14 13:55:04 2013 -0400
@@ -61,7 +61,9 @@
 
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertSame;
+import static org.testng.Assert.assertTrue;
 
+import java.time.Clock;
 import java.time.LocalTime;
 
 import org.testng.annotations.Test;
@@ -176,4 +178,23 @@
         }
     }
 
+    //-----------------------------------------------------------------------
+    // now()
+    //-----------------------------------------------------------------------
+    @Test
+    public void now() {
+        // Warmup the TimeZone data so the following test does not include
+        // one-time initialization
+        LocalTime expected = LocalTime.now(Clock.systemDefaultZone());
+
+        expected = LocalTime.now(Clock.systemDefaultZone());
+        LocalTime test = LocalTime.now();
+        long diff = test.toNanoOfDay() - expected.toNanoOfDay();
+        if (diff < 0) {
+            // Adjust if for rollover around midnight
+            diff +=  24 * 60 * 60 * 1_000_000_000L; // Nanos Per Day
+        }
+        assertTrue(diff < 500000000);  // less than 0.5 secs
+    }
+
 }