United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6957683 TEST_BUG: test/java/util/concurrent/ThreadPoolExecutor/Custom.java failing
JDK-6957683 : TEST_BUG: test/java/util/concurrent/ThreadPoolExecutor/Custom.java failing

Details
Type:
Bug
Submit Date:
2010-06-02
Status:
Closed
Updated Date:
2013-12-17
Project Name:
JDK
Resolved Date:
2012-05-07
Component:
core-libs
OS:
generic
Sub-Component:
java.util.concurrent
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:

Related Reports
Backport:
Backport:
Backport:
Backport:
Backport:
Relates:

Sub Tasks

Description
This test failed for on linux-x86 in JPRT. My forest is essentially jdk7-b95.

--------------------------------------------------
TEST: java/util/concurrent/ThreadPoolExecutor/Custom.java
JDK under test: (/tmp/jprt/T1/T/144354.ab23780/testproduct/linux_x64_2.6-product)
java version "1.7.0-201006011443.ab23780.jdk"
Java(TM) SE Runtime Environment (build 1.7.0-201006011443.ab23780.jdk-jprtadm_2010_06_01_16_06-b00)
Java HotSpot(TM) 64-Bit Server VM (build 19.0-b01, mixed mode)

ACTION: build -- Passed. Build successful
REASON: Named class compiled on demand
TIME:   0.031 seconds
messages:
command: build Custom
reason: Named class compiled on demand
elapsed time (seconds): 0.031

ACTION: compile -- Passed. Compilation successful
REASON: .class file out of date or does not exist
TIME:   0.03 seconds
messages:
command: compile /tmp/jprt/T1/T/144354.ab23780/source/test/java/util/concurrent/ThreadPoolExecutor/Custom.java
reason: .class file out of date or does not exist
elapsed time (seconds): 0.03

ACTION: main -- Failed. Execution failed: `main' threw exception: java.lang.Exception: Some tests failed
REASON: Assumed action based on file name: run main Custom 
TIME:   0.053 seconds
messages:
command: main Custom
reason: Assumed action based on file name: run main Custom 
elapsed time (seconds): 0.053
STDOUT:
1 not equal to 0
11 not equal to 10
1 not equal to 0

Passed = 5, failed = 3

STDERR:
java.lang.Exception: Stack trace
	at java.lang.Thread.dumpStack(Thread.java:1353)
	at Custom.fail(Custom.java:37)
	at Custom.equal(Custom.java:42)
	at Custom.main(Custom.java:105)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:613)
	at com.sun.javatest.regtest.MainAction$SameVMRunnable.run(MainAction.java:680)
	at java.lang.Thread.run(Thread.java:717)
java.lang.Exception: Stack trace
	at java.lang.Thread.dumpStack(Thread.java:1353)
	at Custom.fail(Custom.java:37)
	at Custom.equal(Custom.java:42)
	at Custom.main(Custom.java:111)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:613)
	at com.sun.javatest.regtest.MainAction$SameVMRunnable.run(MainAction.java:680)
	at java.lang.Thread.run(Thread.java:717)
java.lang.Exception: Stack trace
	at java.lang.Thread.dumpStack(Thread.java:1353)
	at Custom.fail(Custom.java:37)
	at Custom.equal(Custom.java:42)
	at Custom.main(Custom.java:115)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:613)
	at com.sun.javatest.regtest.MainAction$SameVMRunnable.run(MainAction.java:680)
	at java.lang.Thread.run(Thread.java:717)
java.lang.Exception: Some tests failed
	at Custom.main(Custom.java:118)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:613)
	at com.sun.javatest.regtest.MainAction$SameVMRunnable.run(MainAction.java:680)
	at java.lang.Thread.run(Thread.java:717)

JavaTest Message: Test threw exception: java.lang.Exception
JavaTest Message: shutting down test


TEST RESULT: Failed. Execution failed: `main' threw exception: java.lang.Exception: Some tests failed
--------------------------------------------------

                                    

Comments
EVALUATION

See also 6712206. These tests have timing delays/assumptions in them that may not be long enough on slow(er) machines. The current failures occur at each marked line:

    public static void main(String[] args) throws Throwable {
        CustomTPE tpe = new CustomTPE();
        equal(tpe.getCorePoolSize(), threadCount);
        equal(countExecutorThreads(), 0);
        for (int i = 0; i < threadCount; i++)
            tpe.submit(new Runnable() { public void run() {}});
        equal(countExecutorThreads(), threadCount);
        equal(CustomTask.births.get(), threadCount);
        tpe.shutdown();
        tpe.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
        Thread.sleep(10);
/*1*/   equal(countExecutorThreads(), 0);

        CustomSTPE stpe = new CustomSTPE();
        for (int i = 0; i < threadCount; i++)
            stpe.submit(new Runnable() { public void run() {}});
        equal(CustomSTPE.decorations.get(), threadCount);
/*2*/   equal(countExecutorThreads(), threadCount);
        stpe.shutdown();
        stpe.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
        Thread.sleep(10);
/*3/    equal(countExecutorThreads(), 0);

        System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
        if (failed > 0) throw new Exception("Some tests failed");
    }

Failures 1 and 3 assume the executor can fully shutdown in 10ms. This requires all 10 worker threads to get the chance to execute and terminate before the test tries to count them.

Failure 2 assumes the executor will fully ramp up and have started all worker threads by the time the test counts them.

The number of processors available and the scheduler details also impact the validity of the test.
                                     
2010-06-02
SUGGESTED FIX

Increasing the internal timeouts and waiting for the threads 
to start with a count doen latch should make this test more reliable 
on slower machines.

diff --git a/test/java/util/concurrent/ThreadPoolExecutor/Custom.java b/test/java/util/concurrent/ThreadPoolExecutor/Custom.java
--- a/test/java/util/concurrent/ThreadPoolExecutor/Custom.java
+++ b/test/java/util/concurrent/ThreadPoolExecutor/Custom.java
@@ -100,18 +100,24 @@
         equal(countExecutorThreads(), threadCount);
         equal(CustomTask.births.get(), threadCount);
         tpe.shutdown();
-        tpe.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
-        Thread.sleep(10);
+        tpe.awaitTermination(120, TimeUnit.SECONDS);
+	Thread.sleep(1000);
         equal(countExecutorThreads(), 0);
 
         CustomSTPE stpe = new CustomSTPE();
+	final CountDownLatch latch = new CountDownLatch(threadCount);
         for (int i = 0; i < threadCount; i++)
-            stpe.submit(new Runnable() { public void run() {}});
+            stpe.submit(new Runnable() {
+		    public void run() {
+			latch.countDown();
+		    }
+		});
+	latch.await();
         equal(CustomSTPE.decorations.get(), threadCount);
         equal(countExecutorThreads(), threadCount);
         stpe.shutdown();
-        stpe.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
-        Thread.sleep(10);
+        stpe.awaitTermination(120, TimeUnit.SECONDS);
+	Thread.sleep(1000);
         equal(countExecutorThreads(), 0);
 
         System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
                                     
2011-11-21
EVALUATION

Leave the defensive timeouts on the awaitTermination and increase sleep delays to give the worker threads a chance to really terminate. 

JDK8 Changeset: 72d8f91514d1
Author:    gadams
Date:      2012-02-08 11:19 +0000
URL:       http://hg.openjdk.java.net/jdk8/tl/jdk/rev/72d8f91514d1

6957683: test/java/util/concurrent/ThreadPoolExecutor/Custom.java failing
Reviewed-by: chegar, dholmes, alanb

! test/java/util/concurrent/ThreadPoolExecutor/Custom.java
                                     
2012-02-08



Hardware and Software, Engineered to Work Together