Skip to content

Conversation

@max611
Copy link
Member

@max611 max611 commented Sep 28, 2018

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 using read_timeout= .

end
end

def test_changes_timeout_when_half_open_and_configured
Copy link
Member Author

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?

Copy link
Contributor

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!

Copy link
Member Author

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.

@max611 max611 requested review from jpittis and sirupsen September 28, 2018 19:31
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 =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change this? 👂

Copy link
Member Author

@max611 max611 Oct 1, 2018

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.

Copy link
Contributor

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.

end
end

def test_changes_timeout_when_half_open_and_configured
Copy link
Contributor

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!


with_semian_configuration(options) do
with_server do
Timecop.travel(10) do
Copy link
Contributor

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!

end
end
open_circuit!
Semian.resources.values.last.mark_failed(nil)
Copy link
Contributor

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.

@max611 max611 force-pushed the half_open_http_net branch 6 times, most recently from 8956e32 to cd7831e Compare October 2, 2018 00:11
@max611 max611 force-pushed the half_open_http_net branch 3 times, most recently from 42dc068 to 81601db Compare October 3, 2018 13:59

private

def half_open_cicuit!(backwards_time_travel = 10)
Copy link
Member Author

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?

Copy link
Contributor

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.

@max611 max611 force-pushed the half_open_http_net branch from 81601db to bfa0828 Compare October 3, 2018 14:13
Copy link
Contributor

@jpittis jpittis left a 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 =
Copy link
Contributor

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.

@max611 max611 force-pushed the half_open_http_net branch from bfa0828 to 0760dc4 Compare October 9, 2018 14:35
@max611 max611 merged commit 7a6ae68 into master Oct 9, 2018
@max611 max611 deleted the half_open_http_net branch October 9, 2018 15:08
@max611 max611 temporarily deployed to rubygems October 19, 2018 15:07 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants