-
-
Notifications
You must be signed in to change notification settings - Fork 573
refactor(tests): Fix flaky ItemizableUpdateService test #5479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
refactor(tests): Fix flaky ItemizableUpdateService test #5479
Conversation
dorner
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately this doesn't seem to work - it's causing failures on CI right now 😦 https://github.com/rubyforgood/human-essentials/actions/runs/21137813115/job/61316145366?pr=5479
0a03229 to
85603b9
Compare
|
Thanks @dorner had a look at the failure and there can be small differences when loading the exact same date from the DB, looked at alternative ways to check the same date and applied them to the assert. |
… removed the global Timecop freeze to be able to order Event entries.
85603b9 to
5c8dd91
Compare
| expect(storage_location.size).to eq(26) | ||
| expect(new_storage_location.size).to eq(20) | ||
| expect(itemizable.issued_at).to eq(2.days.ago) | ||
| expect(itemizable.issued_at.to_fs(:db)).to eq(two_days_ago.to_fs(:db)) # Use to_fs to ignore nanosecond differences |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can use be_within(1.second) alternatively as I see it used in other specs
|
@Sergio-Mira I don't see the purpose in removing the |
Resolves #4496
Description
Fix flaky ItemizableUpdateService test. The issue is caused by the use of Timecop and having order dependence on Event entries in the logic that are ordered by event_time, updated_at.
Looks like that given some specific seeds the order of entries into the DB with the exact same timestamp would then sometimes result in out-of-order (vs entry order) events being returned that would be processed in
InventoryAggregate:inventory_forin the wrong order, causing unexpected results as seen in the screenshot.Recommendation is to not freeze time unless you want the time to be consistent across the test execution, I have instead removed the global time freeze and used it as a block on specific tests to mock
Time.nowsimilarly to what was intended before.Also replaced usage of
subjectwith a method definition as subject is normally and object not a method call, but can revert this change.Type of change
How Has This Been Tested?
Screenshots
How the issue was found
--bisectto try and trim down to the least specs possible. In this case surprisingly it was all tests although manual edits and runs later proved that it could be trimmed down a bit.InventoryAggregate:inventory_forwhere events were being outputted in a different orderorder(:event_time, :updated_at)(note noidin it)It was pretty hard to find, got lucky by getting a seed that would cause a similar issue consistently.