-
Notifications
You must be signed in to change notification settings - Fork 166
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
[v2.x] Add requests timeouts option #246
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# For travis to additionally test rest-client 1.x. | ||
|
||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in kubeclient.gemspec | ||
gemspec | ||
|
||
if dependencies.any? # needed for overriding with recent bundler (1.13 ?) | ||
dependencies.delete('rest-client') | ||
gem 'rest-client', '= 1.8.0' | ||
end |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,15 @@ def test_api_ssl_failure | |
assert_equal(error_message, exception.message) | ||
end | ||
|
||
def test_api_timeout | ||
stub_request(:get, 'http://localhost:8080/api').to_timeout | ||
|
||
client = Kubeclient::Client.new('http://localhost:8080/api/') | ||
|
||
exception = assert_raises(KubeException) { client.api } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cben note that I changed this to |
||
assert_match(/(timed out|timeout)/i, exception.message) | ||
end | ||
|
||
def test_api_valid | ||
stub_request(:get, 'http://localhost:8080/api') | ||
.to_return(status: 200, body: open_test_file('versions_list.json')) | ||
|
@@ -627,6 +636,69 @@ def test_nil_items | |
client.get_persistent_volume_claims | ||
end | ||
|
||
# Timeouts | ||
|
||
def test_timeouts_defaults | ||
client = Kubeclient::Client.new( | ||
'http://localhost:8080/api/' | ||
) | ||
rest_client = client.rest_client | ||
assert_default_open_timeout(rest_client.open_timeout) | ||
assert_equal(60, read_timeout(rest_client)) | ||
end | ||
|
||
def test_timeouts_open | ||
client = Kubeclient::Client.new( | ||
'http://localhost:8080/api/', | ||
timeouts: { open: 10 } | ||
) | ||
rest_client = client.rest_client | ||
assert_equal(10, rest_client.open_timeout) | ||
assert_equal(60, read_timeout(rest_client)) | ||
end | ||
|
||
def test_timeouts_read | ||
client = Kubeclient::Client.new( | ||
'http://localhost:8080/api/', | ||
timeouts: { read: 300 } | ||
) | ||
rest_client = client.rest_client | ||
assert_default_open_timeout(rest_client.open_timeout) | ||
assert_equal(300, read_timeout(rest_client)) | ||
end | ||
|
||
def test_timeouts_both | ||
client = Kubeclient::Client.new( | ||
'http://localhost:8080/api/', | ||
timeouts: { open: 10, read: 300 } | ||
) | ||
rest_client = client.rest_client | ||
assert_equal(10, rest_client.open_timeout) | ||
assert_equal(300, read_timeout(rest_client)) | ||
end | ||
|
||
def test_timeouts_infinite | ||
client = Kubeclient::Client.new( | ||
'http://localhost:8080/api/', | ||
timeouts: { open: nil, read: nil } | ||
) | ||
rest_client = client.rest_client | ||
assert_nil(rest_client.open_timeout) | ||
assert_nil(read_timeout(rest_client)) | ||
end | ||
|
||
def read_timeout(rest_client) | ||
rest_client.send(Kubeclient::ClientMixin.restclient_read_timeout_option) | ||
end | ||
|
||
def assert_default_open_timeout(actual) | ||
if RUBY_VERSION >= '2.3' | ||
assert_equal(60, actual) | ||
else | ||
assert_nil(actual) | ||
end | ||
end | ||
|
||
private | ||
|
||
# dup method creates a shallow copy which is not good in this case | ||
|
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.
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.
@cben I changed
raise
tofail
.