Test waits for thread to exit before destroy
Test waits for thread to exit before destroy

ThreadGroup.destroy throws if a thread is still alive.
There was a race between the thread exiting after setting
a result in a syncvar and the test thread destroying the
thread group.

Cope slightly better with timing issues in tests by
using `waitForIt` to test a termination condition in
a loop, waiting longer if retries are necessary. Nothing
very fancy, just a practical balance between picking
a timeout threshold that works in CI and blocking
forever for events to transition.

The caller gets to say whether to expect the condition
to be satisfied fast or slow. That could matter if
the condition is expensive to evaluate, so busier
waiting is costly, or if the test could be extremely
delayed by system load, so that longer waits may be
necessary.

martijnhoekstra/scala,martijnhoekstra/scala,lrytz/scala,lrytz/scala,scala/scala,martijnhoekstra/scala,scala/scala,scala/scala,lrytz/scala,martijnhoekstra/scala,lrytz/scala,martijnhoekstra/scala,lrytz/scala,scala/scala,lrytz/scala,scala/scala,scala/scala,martijnhoekstra/scala