-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
Allow time to be frozen #55
Conversation
95fe7a2
to
8eac246
Compare
Travis shows one minor failure:
I assume this is because the new |
This is going to take a bit of time to look into. As I remember distinctly the person who fixed this showed that it helped things a bit. Undoing / altering this change feels a bit scary and I don't really use Timecop much. If you want to help / offer some more indepth stuff, that might help get this merged quickly. As for the timeouts, don't worry about those. There are 3-5 tests that are flaky, I do mean to fix them up, but I'm lazy and I've not dedicated enough time to this project in the last 2-3 months. I need to get back on board! In terms of "accepting" it though, it seems ok enough, just want to make sure we alter it in a way that won't nark it for others. |
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.
Code style tweaks:
Remove in-line disabling of cops (I want to get all the cops fixed up, again another chore for me) - See if you can refine the logic to not peeve off rubocop.
Add changelog entry. Mention you are refining existing logic to allow Rails users to use travel_to.
I've extracted the whole timer thread handling into a separate
Done.
The former approach polled loop do
return true if yield
break if Time.now - start_time > wait_time
# ...
end This obviously doesn't work if In my new approach, I'm starting a separate timer thread. The thread just sleeps for @thread = Thread.start do
sleep wait_time
@done = true
end The main thread uses a loop, just like before. But instead of checking loop do
return true if yield
break if timer.done?
# ...
end The huge difference is that Note that the timer thread just sets the |
FYI: I'm going to push some minor changes (the timer spec lacks some cleanup) |
f15d8e5
to
b738ed9
Compare
Spec is fixed now. I've also rebased the PR. |
@sos4nt @luke-hill We can just replace Time.now with |
@ineverov to me, using It might also be safer than using a method that Timecop might mock in the future: travisjeffery/timecop#220 |
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.
As for using one method over the other, I'm kind of agnostic, this enhances the gem so I'm fine with it as is, and if someone comes along later we can tweak it further.
b738ed9
to
e90ce22
Compare
@luke-hill would it be possible to cut a new gem version that includes this fix please? 🙏 |
@temochka One will be cut in rubygems in the next 24hours. |
Thank you @luke-hill! This is great news 🙌 |
SitePrism's
wait_until_true
won't work when freezing time viaTimecop.freeze
or Rails'travel_to
. If you try to do so, aFrozenInTimeError
will be raised.This commit removes the
Time#now
dependency and utilizessleep
instead, which doesn't have such restrictions.