Fix race condition in tests