From 5a11bc7f028dbe54bfc23b4e69aa2687bf53611b Mon Sep 17 00:00:00 2001 From: rriggs Date: Sat, 14 Sep 2013 13:55:04 -0400 Subject: [PATCH] 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 --- .../java/time/tck/java/time/TCKLocalTime.java | 11 ---------- .../time/test/java/time/TestLocalTime.java | 21 +++++++++++++++++++ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/test/java/time/tck/java/time/TCKLocalTime.java b/test/java/time/tck/java/time/TCKLocalTime.java index e0ef94cda..dbba80d1c 100644 --- a/test/java/time/tck/java/time/TCKLocalTime.java +++ b/test/java/time/tck/java/time/TCKLocalTime.java @@ -282,17 +282,6 @@ public class TCKLocalTime extends AbstractDateTimeTest { check(LocalTime.MAX, 23, 59, 59, 999999999); } - //----------------------------------------------------------------------- - // 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) //----------------------------------------------------------------------- diff --git a/test/java/time/test/java/time/TestLocalTime.java b/test/java/time/test/java/time/TestLocalTime.java index ddd7b0f57..d7f04ab5a 100644 --- a/test/java/time/test/java/time/TestLocalTime.java +++ b/test/java/time/test/java/time/TestLocalTime.java @@ -61,7 +61,9 @@ package test.java.time; 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 @@ public class TestLocalTime extends AbstractTest { } } + //----------------------------------------------------------------------- + // 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 + } + } -- GitLab