Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
dpep committed Nov 21, 2023
1 parent 23502a4 commit 6e88259
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/network_resiliency/adapter/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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",
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions spec/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 6e88259

Please sign in to comment.