-
Notifications
You must be signed in to change notification settings - Fork 80
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
Replace Time.now with monotonic in lru cache and resource update #443
Conversation
67abc55
to
17d3054
Compare
b7fcb45
to
297eeab
Compare
5d2afa4
to
4ce482b
Compare
test/lru_hash_test.rb
Outdated
|
||
Timecop.travel(2000) do | ||
@lru_hash.set("d", create_circuit_breaker("d")) | ||
sleep(3) |
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.
Uh, no sleep in test please. The suite is slow enough already.
You can use mocha
to stub Process.clock_gettime
. You can even write a small test helper that would work like Timecop.travel
, would only take 5 lines of code.
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.
I wrote small mock solution for travel. it would require either both Time.now and Monotonic time mocking or merge changes from #441 to single PR -> remove any Time.now usage from semian.
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.
Introduced Time helper to freeze time with +/-duration.
Because circuit breaker requires Time.now for now and LRU hash uses Monotnic did universal stub mechanism for both clocks:
https://github.com/Shopify/semian/pull/443/files#diff-4063630c1592331c02bf7c3561f5eb835eaff847cc9d3bd993ea2488e3492cb3R3
Could you explain, for my learning, the value of this change?. NVM, I just read this |
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.
LGTM. Time.now
is quite a waste of resource in tight loops.
19b1f15
to
b888976
Compare
Resource updated_at is not require be timestamp value. Replaced the value with monotonic time, instead. It requires to update tests - timecop does not support monotonic time changes, replaced timecop with `sleep`. Intorduce TimeHelper to test monotonic.
b888976
to
5ca75c0
Compare
Resource updated_at used only for LRU cache to clean unused resources.
There is no need in keeping timestamp.
Sidecar:
Implement basic travel time helper to cover Monotonic clocks.