Skip to content

Fix flaky TripPlannerViewModel async tests#145

Merged
aaronbrethorst merged 1 commit intomainfrom
fix/flaky-viewmodel-tests
Jan 29, 2026
Merged

Fix flaky TripPlannerViewModel async tests#145
aaronbrethorst merged 1 commit intomainfrom
fix/flaky-viewmodel-tests

Conversation

@aaronbrethorst
Copy link
Member

@aaronbrethorst aaronbrethorst commented Jan 29, 2026

Summary

Fixes intermittent CI test failures in TripPlannerViewModelTests that have been affecting all recent builds on the main branch.

Root Cause

The async tests were using a fixed Task.sleep(nanoseconds: 200_000_000) (0.2 seconds) to wait for async operations to complete. This duration is insufficient on slower CI machines, causing tests to check assertions before the async operations finish.

Changes

  • Added waitForLoadingComplete() helper function that polls viewModel.isLoading every 50ms with a 5-second timeout
  • Updated 8 tests to use the polling helper instead of fixed sleep

Tests Fixed

  • planTrip succeeds with valid locations
  • planTrip sets loading state correctly
  • planTrip handles API errors
  • planTrip clears previous errors
  • planTrip uses wheelchair accessible setting
  • planTrip uses maxWalkDistance setting
  • planTrip uses arriveBy when timePreference is arriveBy
  • planTrip uses leaveNow time preference

Test plan

  • All 137 tests pass locally
  • SwiftLint passes
  • CI tests pass

Replace fixed Task.sleep(0.2s) calls with a polling helper function
that waits for isLoading to become false with a 5-second timeout.

The fixed sleep duration was insufficient on slower CI machines,
causing intermittent test failures for:
- planTrip succeeds with valid locations
- planTrip sets loading state correctly
- planTrip handles API errors
@aaronbrethorst aaronbrethorst merged commit 13da0ba into main Jan 29, 2026
3 checks passed
@aaronbrethorst aaronbrethorst deleted the fix/flaky-viewmodel-tests branch January 29, 2026 03:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant