Fix race condition in test