Index: modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadGroupTest.java =================================================================== --- modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadGroupTest.java (revision 451095) +++ modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadGroupTest.java (working copy) @@ -153,6 +153,8 @@ t1.join(); } catch (InterruptedException e) { } + // cleanup + tg.destroy(); } /** @@ -337,7 +339,6 @@ ThreadGroup testRoot = new ThreadGroup(originalCurrent, "Test group"); boolean passed = true; - passed = true; try { testRoot.setMaxPriority(Thread.MIN_PRIORITY); } catch (IllegalArgumentException iae) { @@ -448,7 +449,7 @@ // java.lang.Thread boolean result = wipeSideEffectThreads(originalCurrent); if (result == false) { - System.out.println("wipe threads in test_list() not successful"); + fail("wipe threads in test_list() not successful"); } final ThreadGroup testRoot = new ThreadGroup(originalCurrent, "Test group"); @@ -465,7 +466,6 @@ System.setOut(newOut); originalCurrent.list(); - byte[] contents = contentsStream.toByteArray(); /* * The output has to look like this @@ -475,15 +475,13 @@ * */ - boolean passed = verifyThreadList(originalCurrent, testRoot, - contents); - - assertTrue( - "Either 'list' is wrong or other tests are leaving side-effects.\n" - + "Result from list:\n " + "-----------------\n " - + new String(contents, 0, contents.length) - + "\n-----------------\n ", passed); - + String contents = new String(contentsStream.toByteArray()); + boolean passed = (contents.indexOf("ThreadGroup[name=main") != -1) && + (contents.indexOf("Thread[") != -1) && + (contents.indexOf("ThreadGroup[name=Test group") != -1); + assertTrue("'list()' does not print expected contents. " + + "Result from list: " + + contents, passed); // Do proper cleanup testRoot.destroy(); @@ -644,9 +642,9 @@ currentMax = testRoot.getMaxPriority(); testRoot.setMaxPriority(Thread.MIN_PRIORITY - 1); - passed = testRoot.getMaxPriority() == Thread.MIN_PRIORITY; + passed = testRoot.getMaxPriority() == currentMax; assertTrue( - "setMaxPriority: Any value smaller than MIN_PRIORITY is adjusted to MIN_PRIORITY. Before: " + "setMaxPriority: Any value smaller than MIN_PRIORITY is ignored. Before: " + currentMax + " , after: " + testRoot.getMaxPriority(), passed); @@ -851,7 +849,22 @@ // We can't destroy a ThreadGroup if we do not make sure it has no // threads at all - + testRoot.stop(); + long waitTime = 5000; + for (int i = 0; i < threads.size(); i++) { + Thread t = threads.elementAt(i); + while (t.isAlive() && waitTime >= 0) { + try { + Thread.sleep(10); + waitTime -= 10; + } catch (InterruptedException e) { + fail("unexpected interruption"); + } + } + if (waitTime < 0) { + fail("stop() has not stopped threads in ThreadGroup 'testRoot'"); + } + } // Make sure we cleanup before returning from the method testRoot.destroy(); } @@ -1314,29 +1327,6 @@ } - private boolean verifyThreadList(ThreadGroup root, - ThreadGroup onlyChildGroup, byte[] listOutput) { - // We expect that @root has only 1 subgroup, @onlyChildGroup. The - // output from method 'list' is stored in @listOutput - if (listOutput.length == 0) { - return false; - } - - // If we got a long output, it means some previous test must have left - // side-effects (more subgroups and threads); - final int MAX_SIZE = 200; - if (listOutput.length > MAX_SIZE) { - return false; - } - - // Here we compare actual result to expected result - - // Due to extremely weak API in String, comparing substrings, etc would - // take too much work at this time. - // We defer the actual implementation for now. - return true; - } - private boolean allSuspended(Vector threads) { for (int i = 0; i < threads.size(); i++) { MyThread t = threads.elementAt(i);