fix(test): freeze time in tests to prevent flaky failures#2568
Open
mroderick wants to merge 1 commit intocodebar:masterfrom
Open
fix(test): freeze time in tests to prevent flaky failures#2568mroderick wants to merge 1 commit intocodebar:masterfrom
mroderick wants to merge 1 commit intocodebar:masterfrom
Conversation
Remove timecop gem dependency and use Rails' travel_to helper. Time-based scopes compare against Time.zone.now evaluated at query time, while test fixtures used relative times evaluated at creation time. This caused flaky tests when any time passed between fixture creation and query. Files changed: - Remove timecop from Gemfile and test.rb config - Add travel_to blocks to time-dependent tests in shared examples, listable_spec, attendance_warning_spec, feature tests, rake tasks, and presenter specs Fixes flaky test failures in CI runs.
5e1ea55 to
3f44835
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Remove
timecopgem dependency and fix flaky tests caused by time-based comparisons without freezing time.Problem
CI was failing due to flaky tests. The root cause: time-based scopes compare against
Time.zone.nowevaluated at query time, while test fixtures use relative times (2.days.ago,1.week.from_now) evaluated at creation time. Any time gap between fixture creation and query execution could cause incorrect results.Solution
Wrap time-dependent tests in
travel_to(Time.current)blocks, ensuring all time calculations reference the same frozen moment.Files Changed
Gemfile,Gemfile.lock- Remove timecop dependencyconfig/environments/test.rb- Remove timecop require and configspec/support/shared_examples/behaves_like_an_invitation.rb- Freeze time in invitation scope testsspec/models/concerns/listable_spec.rb- Replace Timecop with travel_to, add time freezingspec/models/attendance_warning_spec.rb- Freeze time in last_six_months testspec/features/*- Freeze time in feature tests with relative datesspec/presenters/*- Freeze time in presenter testsspec/lib/tasks/*- Freeze time in rake task testsTest Plan
travel_toovertimecopFixes flaky test failures in CI.