RFR for bug JDK-8004807: java/util/Timer/Args.java failing intermittently in HS testing

Eric Wang yiming.wang at oracle.com
Wed Jun 4 06:28:35 UTC 2014


Hi Martin,

Thanks for explanation, now I can understand why you set the DELAY_MS to 
100 seconds, it is true that it prevents failure on a slow host, 
however, i still have some concerns.
Because the test tests to schedule tasks at the time in the past, so all 
13 tasks should be executed immediately and finished within a short time.
If set the elapsed time limitation to 50s (DELAY_MS/2), it seems that 
the timer have plenty of time to finish tasks, so whether it causes 
above test point lost.

Back to the original test, i think it should be a test stabilization 
issue, because the original test assumes that the timer should be 
cancelled within < 1 second before the 14th task is called. this 
assumption may not be guaranteed due to 2 reasons:
1. if test is executed in jtreg concurrent mode on a slow host.
2. the system clock of virtual machine may not be accurate (maybe faster 
than physical).

To support the point, i changed the test as attached to print the 
execution time to see whether the timer behaves expected as the API 
document described. the result is as expected.

The unrepeated task executed immediately: [1401855509336]
The repeated task executed immediately and repeated per 1 second: 
[1401855509337, 1401855510337, 1401855511338]
The fixed-rate task executed immediately and catch up the delay: 
[1401855509338, 1401855509338, 1401855509338, 1401855509338, 
1401855509338, 1401855509338, 1401855509338, 1401855509338, 
1401855509338, 1401855509338, 1401855509338, 1401855509836, 1401855510836]


Thanks,
Eric
On 2014/6/4 9:16, Martin Buchholz wrote:
>
>
>
> On Tue, Jun 3, 2014 at 6:12 PM, Eric Wang <yiming.wang at oracle.com 
> <mailto:yiming.wang at oracle.com>> wrote:
>
>     Hi Martin,
>
>     To sleep(1000) is not enough to reproduce the failure, because it
>     is much lower than the period DELAY_MS (10*1000) of the repeated
>     task created by "scheduleAtFixedRate(t, counter(y3), past, DELAY_MS)".
>
>     Try sleep(DELAY_MS), the failure can be reproduced.
>
>
> Well sure, then the task is rescheduled, so I expect it to fail in 
> this case.
>
> But in my version I had set DELAY_MS to 100 seconds.  The point of 
> extending the DELAY_MS is to prevent flaky failure on a slow machine.
>
> Again, how do we know that this test hasn't found a Timer bug?
>
> I still can't reproduce it.

-------------- next part --------------
diff -r a02731d3f739 test/java/util/Timer/Args.java
--- a/test/java/util/Timer/Args.java	Thu May 29 22:32:11 2014 -0700
+++ b/test/java/util/Timer/Args.java	Wed Jun 04 14:17:57 2014 +0800
@@ -49,9 +49,9 @@
                new F(){void f(){ t.scheduleAtFixedRate(task, d, period); }});
     }
 
-    TimerTask counter(final CountDownLatch latch) {
+    TimerTask counter(final CountDownLatch latch, final ArrayList<Long> list) {
         return new TimerTask() { public void run() {
-            check(latch.getCount() > 0);
+            list.add(System.currentTimeMillis());
             latch.countDown();
         }};
     }
@@ -97,10 +97,12 @@
         final CountDownLatch y3 = new CountDownLatch(11);
         final long start = System.currentTimeMillis();
         final Date past = new Date(start - 10500);
-
-        schedule(           t, counter(y1), past);
-        schedule(           t, counter(y2), past, 1000);
-        scheduleAtFixedRate(t, counter(y3), past, 1000);
+        ArrayList<Long> l1 = new ArrayList<>();
+        ArrayList<Long> l2 = new ArrayList<>();
+        ArrayList<Long> l3 = new ArrayList<>();
+        schedule(           t, counter(y1, l1), past);
+        schedule(           t, counter(y2, l2), past, 1000);
+        scheduleAtFixedRate(t, counter(y3, l3), past, 1000);
         y3.await();
         y1.await();
         y2.await();
@@ -108,9 +110,11 @@
         final long elapsed = System.currentTimeMillis() - start;
         System.out.printf("elapsed=%d%n", elapsed);
         check(elapsed < 500);
-
+        Thread.sleep(2000);
         t.cancel();
-
+        System.out.println("l1 " + Objects.toString(l1));
+        System.out.println("l2 " + Objects.toString(l2));
+        System.out.println("l3 " + Objects.toString(l3));
         THROWS(IllegalStateException.class,
                new F(){void f(){ t.schedule(x, 42); }},
                new F(){void f(){ t.schedule(x, past); }},


More information about the core-libs-dev mailing list