Fix race condition in test using a sleep().