Fixing race condition in test