Fix timing issues in tests