mockdeep / better

Open. Democratic. Project management platform.
bettermeans.com
51 stars 19 forks source link

Fix inconsistent model tests #94

Closed mockdeep closed 4 years ago

mockdeep commented 4 years ago

For some reason Issue#lazy_majority_passed? was super flaky. It was returning true or false seemingly at random. When I put in a debugger, I got similar results when doing the date/time comparison repeatedly:

(rdb:1) updated_at < DateTime.now - Setting::LAZY_MAJORITY_LENGTH
true
(rdb:1) updated_at < DateTime.now - Setting::LAZY_MAJORITY_LENGTH
true
(rdb:1) updated_at < DateTime.now - Setting::LAZY_MAJORITY_LENGTH
false
(rdb:1) updated_at < DateTime.now - Setting::LAZY_MAJORITY_LENGTH
false
(rdb:1) updated_at < DateTime.now - Setting::LAZY_MAJORITY_LENGTH
false
(rdb:1) updated_at < DateTime.now - Setting::LAZY_MAJORITY_LENGTH
true

I poked around with different options, converting to UTC and so forth, but the same issue presented itself. There's more than 24 hours between the values, so time zones shouldn't be an issue anyway. I settled on converting to string, which I feel pretty confident works as expected. The tests passed consistently over several runs, at any rate.

I suspect this is an obscure bug in ActiveSupport, but didn't feel it was worth too deep an investigation, because, fingers crossed, this issue will hopefully have been resolved in a more recent version of Ruby/Rails.

I needed to convert updated_at.to_datetime because updated_at.to_s(:iso8601) returns a string in a different format that is not lexically sortable. It starts with the day of the week, Sat, Sun, etc.