From 6e8825910097eb6404f3b1bd33fda07919edec27 Mon Sep 17 00:00:00 2001 From: Daniel Pepper Date: Tue, 21 Nov 2023 09:11:41 -0800 Subject: [PATCH] bugfix --- lib/network_resiliency/adapter/http.rb | 9 ++++----- spec/http_spec.rb | 7 +++++++ spec/redis_spec.rb | 1 + 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/network_resiliency/adapter/http.rb b/lib/network_resiliency/adapter/http.rb index 20b2895..ad23ea1 100644 --- a/lib/network_resiliency/adapter/http.rb +++ b/lib/network_resiliency/adapter/http.rb @@ -50,6 +50,9 @@ def with_resilience(action, destination, idempotent, &block) timeouts = timeouts.last(1) end + original_max_retries = self.max_retries + self.max_retries = 0 # disable + attempts = 0 ts = -NetworkResiliency.timestamp @@ -73,6 +76,7 @@ def with_resilience(action, destination, idempotent, &block) ensure ts += NetworkResiliency.timestamp set_timeout.call(original_timeout) + self.max_retries = original_max_retries NetworkResiliency.record( adapter: "http", @@ -107,12 +111,7 @@ def transport_request(req, &block) idepotent = Net::HTTP::IDEMPOTENT_METHODS_.include?(req.method) - retries = self.max_retries - self.max_retries = 0 # disable - with_resilience(:request, destination, idepotent) { super } - ensure - self.max_retries = retries end end end diff --git a/spec/http_spec.rb b/spec/http_spec.rb index a1df533..50b91d2 100644 --- a/spec/http_spec.rb +++ b/spec/http_spec.rb @@ -274,6 +274,13 @@ end end end + + context "when NetworkResiliency is disabled" do + before { NetworkResiliency.disable! } + + it { is_expected.to eq "OK" } + it { expect(NetworkResiliency).not_to have_received(:record) } + end end describe "normalize path" do diff --git a/spec/redis_spec.rb b/spec/redis_spec.rb index e423bdc..f8808a6 100644 --- a/spec/redis_spec.rb +++ b/spec/redis_spec.rb @@ -253,6 +253,7 @@ context "when NetworkResiliency is disabled" do before { NetworkResiliency.disable! } + it { expect(redis.ping).to eq "PONG" } it { is_expected.not_to have_received(:record) } end