changeset 11855:04f51cc56673

8078369: [testbug] java/time/tck/java/time/TCKOffsetTime[now] fails on slow devices Summary: Increase the tolerance between successive calls to now() to 20sec Reviewed-by: scolebourne, sherman, dfuchs
author rriggs
date Mon, 27 Apr 2015 16:31:47 -0400
parents 76b64929271b
children 9ee8794f584f
files test/java/time/tck/java/time/TCKLocalDateTime.java test/java/time/tck/java/time/TCKOffsetDateTime.java test/java/time/tck/java/time/TCKOffsetTime.java
diffstat 3 files changed, 16 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/time/tck/java/time/TCKLocalDateTime.java	Mon Apr 27 21:02:40 2015 +0800
+++ b/test/java/time/tck/java/time/TCKLocalDateTime.java	Mon Apr 27 16:31:47 2015 -0400
@@ -107,8 +107,6 @@
 import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
 
-import java.io.ByteArrayOutputStream;
-import java.io.DataOutputStream;
 import java.time.Clock;
 import java.time.DateTimeException;
 import java.time.DayOfWeek;
@@ -260,16 +258,17 @@
     //-----------------------------------------------------------------------
     @Test(timeOut=30000)  // TODO: remove when time zone loading is faster
     public void now() {
+        final long DELTA = 20_000_000_000L;    // 20 seconds of nanos leeway
         LocalDateTime expected = LocalDateTime.now(Clock.systemDefaultZone());
         LocalDateTime test = LocalDateTime.now();
         long diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay());
-        if (diff >= 100000000) {
+        if (diff >= DELTA) {
             // may be date change
             expected = LocalDateTime.now(Clock.systemDefaultZone());
             test = LocalDateTime.now();
             diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay());
         }
-        assertTrue(diff < 100000000);  // less than 0.1 secs
+        assertTrue(diff < DELTA);
     }
 
     //-----------------------------------------------------------------------
--- a/test/java/time/tck/java/time/TCKOffsetDateTime.java	Mon Apr 27 21:02:40 2015 +0800
+++ b/test/java/time/tck/java/time/TCKOffsetDateTime.java	Mon Apr 27 16:31:47 2015 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -104,8 +104,6 @@
 import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
 
-import java.io.ByteArrayOutputStream;
-import java.io.DataOutputStream;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.time.Clock;
@@ -235,16 +233,17 @@
     //-----------------------------------------------------------------------
     @Test
     public void now() {
+        final long DELTA = 20_000_000_000L;    // 20 seconds of nanos leeway
         OffsetDateTime expected = OffsetDateTime.now(Clock.systemDefaultZone());
         OffsetDateTime test = OffsetDateTime.now();
         long diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay());
-        if (diff >= 100000000) {
+        if (diff >= DELTA) {
             // may be date change
             expected = OffsetDateTime.now(Clock.systemDefaultZone());
             test = OffsetDateTime.now();
             diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay());
         }
-        assertTrue(diff < 100000000);  // less than 0.1 secs
+        assertTrue(diff < DELTA);
     }
 
     //-----------------------------------------------------------------------
--- a/test/java/time/tck/java/time/TCKOffsetTime.java	Mon Apr 27 21:02:40 2015 +0800
+++ b/test/java/time/tck/java/time/TCKOffsetTime.java	Mon Apr 27 16:31:47 2015 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -89,8 +89,6 @@
 import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
 
-import java.io.ByteArrayOutputStream;
-import java.io.DataOutputStream;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.time.Clock;
@@ -202,12 +200,19 @@
     //-----------------------------------------------------------------------
     @Test
     public void now() {
+        final long DELTA = 20_000_000_000L;    // 20 seconds of nanos leeway
         ZonedDateTime nowDT = ZonedDateTime.now();
 
         OffsetTime expected = OffsetTime.now(Clock.systemDefaultZone());
         OffsetTime test = OffsetTime.now();
         long diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay());
-        assertTrue(diff < 100000000);  // less than 0.1 secs
+        if (diff >= DELTA) {
+            // may be date change
+            expected = OffsetTime.now(Clock.systemDefaultZone());
+            test = OffsetTime.now();
+            diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay());
+        }
+        assertTrue(diff < DELTA);
         assertEquals(test.getOffset(), nowDT.getOffset());
     }