Fix race condition in test setup