-
Notifications
You must be signed in to change notification settings - Fork 79
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
Add half_open_resource_timeout for net http #198
Conversation
719349b
to
8eea4bb
Compare
@@ -42,6 +42,40 @@ def test_semian_identifier | |||
end | |||
end | |||
|
|||
def test_changes_timeout_when_half_open_and_configured |
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'm not sure if I'm doing this right, is there a better way of half opening the circuit?
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.
There's half_open_circuit!
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 think I'll need help with this test, I can't seem to be able to trigger the right thing. I do hit the with_resource_timeout
path but ReadTimeout
does not raise.
if half_open? && @half_open_resource_timeout && resource.respond_to?(:with_resource_timeout) | ||
resource.with_resource_timeout(@half_open_resource_timeout) do | ||
result = block.call | ||
result = |
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.
Why change 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.
Small bikeshed, I can bring back the old syntax. I am used to assigning the value directly from the if, not sure which syntax you guys prefer.
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.
Just for context: The reason this kind of thing might frowned upon is because it causes a 7 line diff that we have to review manually to ensure that a typo size bug isn't added to the library.
@@ -42,6 +42,40 @@ def test_semian_identifier | |||
end | |||
end | |||
|
|||
def test_changes_timeout_when_half_open_and_configured |
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.
There's half_open_circuit!
test/net_http_test.rb
Outdated
|
||
with_semian_configuration(options) do | ||
with_server do | ||
Timecop.travel(10) do |
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.
Can you use an error_timeout
variable or index the proc? Makes this easier to understand!
test/net_http_test.rb
Outdated
end | ||
end | ||
open_circuit! | ||
Semian.resources.values.last.mark_failed(nil) |
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.
Please don't use these low-level APIs 😬 Can you trigger a real failure here like the other tests? This is very implementation specific.
8956e32
to
cd7831e
Compare
42dc068
to
81601db
Compare
@@ -396,6 +432,12 @@ def test_persistent_state_after_server_restart | |||
|
|||
private | |||
|
|||
def half_open_cicuit!(backwards_time_travel = 10) |
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.
@sirupsen I wanted to use the CircuitBreakerHelper but the half_open_circuit!
method uses a open_circuit!
method with an argument and when I call half_open_circuit!
from the net_http_test
file, it calls the open_circuit!
method inside net_http_test
instead of the open_circuit!
method inside the helper which raises. To make it work, I would have to change the open_circuit!
method name everywhere. What do you think of simply keeping the half_open_cicuit!
method in the net_http_test
file?
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.
That's fine with me.
81601db
to
bfa0828
Compare
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.
if half_open? && @half_open_resource_timeout && resource.respond_to?(:with_resource_timeout) | ||
resource.with_resource_timeout(@half_open_resource_timeout) do | ||
result = block.call | ||
result = |
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.
Just for context: The reason this kind of thing might frowned upon is because it causes a 7 line diff that we have to review manually to ensure that a typo size bug isn't added to the library.
bfa0828
to
0760dc4
Compare
The
half_open_resource_timeout
feature was introduced here #188 but only for mysql2.This PR adds it for the
net_http
adapter.Net::HTTP
let us assign the timeout by usingread_timeout=
.