Added better theading support for tests.