Fixing a race condition in a test