Avoid race condition in unit test