Deflake OldThreadGroupTest.

This test temporarily runs background threads, then makes assertions
about the ThreadGroup's threads, such as that they are the same
initially as after the temporary threads have been killed.

Before this CL, the ThreadGroup hosting those background threads,
initialThreadGroup, was the current (test runner) thread's ThreadGroup.
This made the test depend on the inappropriate assumption that threads
would not start or stop in that ThreadGroup during the test runtime.
Therefore, the test was flaky.

This CL moves initialThreadGroup to be a child of the test runner's
ThreadGroup, isolating the test from any unrelated threads that may
be starting or stopping while the test is running, eliminating this
source of flakiness.

The test also asserts that an unrelated thread remains in the
initialThreadGroup throughout the test. It used to use the current
(test runner) thread for this; since initialThreadGroup has changed
to no longer contain that thread, this CL introduces a separate thread,
initialThread, that runs for the entire time from setUp() until
tearDown().

Because the ThreadGroup(String) constructor, which constructs a
ThreadGroup whose parent ThreadGroup is that of the current thread,
was no longer exercised by the changed code, this CL also adds a
new separate test method, test_getParent().

Some unrelated dead code in the test was not addressed as part of
this CL.

Bug: 22106064
Test: make cts && cts-tradefed run cts -m CtsLibcoreTestCases \
      -t libcore.java.lang.OldThreadGroupTest

Change-Id: I1288987a1313eb0ff70a4f6b6022e06422b0fd6f
1 file changed