Skip to content

Conversation

@AhmedAlian7
Copy link
Contributor

Summary

This PR fixes a known flaky test in TestStopsForRouteHandlerEndToEnd where the number of returned stops would fluctuate between 21 and 22 depending on execution order.

closes #336

Changes Made

internal/restapi/stops_for_route_handler.go

  • Fix: Added sort.Slice to sort the tripsInGroup slice by Trip.ID before selecting the representative trip.
  • Impact: This ensures that the representativeTrip selection is deterministic. The same trip is now always chosen to represent the group, resulting in a consistent list of stops every time.

internal/restapi/stops_for_route_handler_test.go

  • Update: Removed the conditional assertion that accepted either 21 or 22 stops.
  • Update: Hardcoded strict expectations:
    • Inbound: Expect exactly 21 stops.
    • Outbound: Expect exactly 22 stops.

Verification

Ran the test 10 times locally to ensure flakiness is resolved.

go test -v -count=10 -tags sqlite_fts5 ./internal/restapi/... -run TestStopsForRouteHandlerEndToEnd

Copy link
Member

@aaronbrethorst aaronbrethorst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Ahmed, nice detective work tracking down the root cause of this flaky test — Go's nondeterministic map iteration was indeed the culprit, and sorting tripsInGroup by trip ID before picking the representative is a clean, correct fix. The tightened assertions removing the TODO workaround are a welcome improvement too. Before we can merge this, I need you to make one change:

Important

1. Squash and rebase

The branch has three commits (including a merge commit) and is six commits behind main. Please squash into a single atomic commit and rebase against main. If rebasing feels unfamiliar, here's a short guide that might help: https://www.brethorsting.com/blog/2026/01/git-rebase-for-the-terrified/

Thanks again, and I look forward to merging this change.

@AhmedAlian7 AhmedAlian7 force-pushed the fix/flaky-stops-for-route-test branch 3 times, most recently from f6d6109 to 4394e81 Compare February 9, 2026 12:30
@AhmedAlian7 AhmedAlian7 force-pushed the fix/flaky-stops-for-route-test branch from 4394e81 to a17ed5f Compare February 9, 2026 12:59
@AhmedAlian7
Copy link
Contributor Author

Hi Aaron, thnx for the feedback and for sharing the article, which was a great help!
I have updated the PR as requested. It’s now ready for your review.

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.

Refactor: Fix Flaky Route Tests

2 participants