Fix potential race condition in test try..catch