Added opt-in feature to scale sleep operations. #124
Closed
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.
A lot of my time-dependent code I work with uses sleep operations with specific timings for scheduling events. These time-dependent snippets are also coupled with the Time-related operations that Timecop already stubs, so the two types of operations always need to be stubbed together for me. I'm currently using some localized stubbing but I'm now finding it necessary to duplicate this code in several test, so I thought I'd submit a pull request to stub sleep when scale is called.
To be specific, it's usually
ConditionVariable#wait
and notKernel#sleep
that I use, but this pull request mocks both, because it is nearly the same operation.This is a purely opt-in feature and shouldn't change the way
Timecop.scale
works for people already using Timecop in the workflows. You can opt-in to this expanded stubbing withTimecop.scale_sleep = true
.I've tried to match the existing style as much as possible in the implementation, the tests, and the explanation I added to the README (which is in a separate commit, so you can decide if you want it or not).
Let me know if you'd prefer some other way of enabling the feature instead of
Timecop.scale_sleep = true
, and I'd bet we can make it happen.Thanks for your consideration, and great work so far with Timecop!