Fixed race conditions in tests