diff options
| -rw-r--r-- | .gitlab-ci.yml | 1 | ||||
| -rw-r--r-- | .travis.yml | 4 | ||||
| -rw-r--r-- | lib/net/hippie/client.rb | 4 | ||||
| -rw-r--r-- | lib/net/hippie/version.rb | 2 | ||||
| -rw-r--r-- | test/net/client_test.rb | 18 |
5 files changed, 22 insertions, 7 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 82d5b2b..b62a94c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,4 +9,3 @@ before_script: ci: script: - bin/cibuild - diff --git a/.travis.yml b/.travis.yml index 2a69cb1..14b18cf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,8 @@ sudo: false language: ruby cache: bundler rvm: - - 2.5.1 + - 2.3.8 + - 2.4.5 + - 2.5.3 script: - bin/cibuild diff --git a/lib/net/hippie/client.rb b/lib/net/hippie/client.rb index 0c94e4a..edd31ba 100644 --- a/lib/net/hippie/client.rb +++ b/lib/net/hippie/client.rb @@ -71,11 +71,11 @@ module Net # attempt 7 -> delay 64 second # attempt 8 -> delay 128 second def with_retry(retries: 3) - retries = 3 if retries <= 0 + retries = 0 if retries.nil? || retries.negative? 0.upto(retries) do |n| return yield self rescue *::Net::Hippie::CONNECTION_ERRORS => error - raise error if n >= retries + raise error if n == retries delay = (2**n) + rand(0.5) # delay + jitter warn("`#{error.message}` Retry: #{n + 1}/#{retries} Delay: #{delay}s") diff --git a/lib/net/hippie/version.rb b/lib/net/hippie/version.rb index 71b849e..3c78850 100644 --- a/lib/net/hippie/version.rb +++ b/lib/net/hippie/version.rb @@ -2,6 +2,6 @@ module Net module Hippie - VERSION = '0.2.0' + VERSION = '0.2.1' end end diff --git a/test/net/client_test.rb b/test/net/client_test.rb index d44a336..9ffd67f 100644 --- a/test/net/client_test.rb +++ b/test/net/client_test.rb @@ -23,13 +23,27 @@ class ClientTest < Minitest::Test WebMock.stub_request(:get, uri.to_s) .to_timeout.then .to_timeout.then + .to_timeout.then .to_return(status: 200, body: { 'success' => 'true' }.to_json) response = subject.with_retry(retries: 3) do |client| client.get(uri) end refute_nil response - assert_equal response.class, Net::HTTPOK - assert_equal('true', JSON.parse(response.body)['success']) + assert_equal Net::HTTPOK, response.class + assert_equal JSON.parse(response.body)['success'], 'true' + end + + def test_exceeds_retries + uri = URI.parse('https://www.example.org/api/scim/v2/schemas') + WebMock.stub_request(:get, uri.to_s) + .to_timeout.then + .to_return(status: 200, body: { 'success' => 'true' }.to_json) + + assert_raises Net::OpenTimeout do + subject.with_retry(retries: 0) do |client| + client.get(uri) + end + end end def test_get_with_string_uri |
