-
Notifications
You must be signed in to change notification settings - Fork 555
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
Move to monotonic time for duration calculations #857
Merged
Merged
Conversation
This file contains 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
Drops the use of `Time.now` in favor of using the system's monotonic clock for various operations that calculate and use elapsed duration. The latter is preferable because in some cases `Time.now` can be unstable, like if it's set manually by a system administrator or an NTP daemon. I don't expect that the previous code would actually have caused trouble in the vast majority of normal situations, so I'm not going to backport anything, but this seems like good hygiene. For better or worse I had to wrap the monotonic time calls in a new `Util` function because (1) the normal invocation is long enough to have caused a lot of overruns on our 80 character line lengths, and (2) Timecop doesn't stub the monotonic clock, so the `Util` method gives us a nice place that we can stub on where necessary.
ob-stripe
approved these changes
Oct 1, 2019
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.
Nice! LGTM
brandur-stripe
pushed a commit
that referenced
this pull request
Oct 1, 2019
If #857 comes in, it turns out that we don't need Timecop anymore (it doesn't freeze the monotic clock, so I had to find another way) -- here we remove all mentions of it and drop the dependency. I don't find it causes too much trouble so I'm not against bringing it back in the future if we need it again, but it seems good for project cleanliness to take it out for now.
Thanks! |
Released as 5.4.0. |
brandur-stripe
pushed a commit
that referenced
this pull request
Oct 1, 2019
If #857 comes in, it turns out that we don't need Timecop anymore (it doesn't freeze the monotic clock, so I had to find another way) -- here we remove all mentions of it and drop the dependency. I don't find it causes too much trouble so I'm not against bringing it back in the future if we need it again, but it seems good for project cleanliness to take it out for now.
Merged
brandur-stripe
pushed a commit
that referenced
this pull request
Oct 1, 2019
If #857 comes in, it turns out that we don't need Timecop anymore (it doesn't freeze the monotic clock, so I had to find another way) -- here we remove all mentions of it and drop the dependency. I don't find it causes too much trouble so I'm not against bringing it back in the future if we need it again, but it seems good for project cleanliness to take it out for now.
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.
Drops the use of
Time.now
in favor of using the system's monotonicclock for various operations that calculate and use elapsed duration.
The latter is preferable because in some cases
Time.now
can beunstable, like if it's set manually by a system administrator or an NTP
daemon.
I don't expect that the previous code would actually have caused trouble
in the vast majority of normal situations, so I'm not going to backport
anything, but this seems like good hygiene.
For better or worse I had to wrap the monotonic time calls in a new
Util
function because (1) the normal invocation is long enough to havecaused a lot of overruns on our 80 character line lengths, and (2)
Timecop doesn't stub the monotonic clock, so the
Util
method gives usa nice place that we can stub on where necessary.
r? @ob-stripe
cc @stripe/api-libraries