From dc612620ab4b9704519e37aa168c5c2d9c083bd1 Mon Sep 17 00:00:00 2001 From: mo Date: Sat, 10 Nov 2018 19:39:33 -0700 Subject: fix off by one on retry logic. --- test/net/client_test.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'test') 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 @@ -21,6 +21,7 @@ class ClientTest < Minitest::Test def test_get_with_retry uri = URI.parse('https://www.example.org/api/scim/v2/schemas') 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) @@ -28,8 +29,21 @@ class ClientTest < Minitest::Test 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 -- cgit v1.2.3