Fixes race conditions in tests.