Fix flaky distributions by county system spec #4910
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Doesn't resolve any issue. Related to #4557
Description
I noticed these distributions by county system specs are still flaky. See this CI failure: https://github.com/rubyforgood/human-essentials/actions/runs/12568036610/job/35035172689?pr=4908
Example rspec output:
Reason for flakiness:
We should be returning counties for the valid distribution, but no distribution is found. The test seems to be only flaky during certain times of day, specifically at times when the time difference between PST and UTC results in different days.
The system time zone (for Capybara) and server time zone (Rails) are in PST. But timestamps are stored in the database in UTC time. Normally this isn't an issue because Active Record will convert to UTC for queries. But since this is a raw SQL query we need to convert to UTC. Otherwise the timezone provided is silently ignored. From Postgres docs:
Note this is not an issue for production though, because the timezone in production is the default (UTC).
Another solution would be to change the timezone for the test environment to UTC, but there might be a reason for it being Los Angeles time.
Type of change
How Has This Been Tested?
In order add a test for this that reliably fails, we would need to add a JS package to mock the time in the browser (because
travel_to
only sets the time for Rails server, but the headless chrome browser for Capybara will still have the regular time).Instead to reliably reproduce the failure, I manually set the time to the time at which the CI test failed and indeed this change fixes the issue).