Fix race condition in test case