Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/http/retriable/performer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ def perform(client, req, &block)
elsif res
return res
end

# re-trigger each feature, we are about to start the request again
client.default_options.features.each_value do |feature|
feature.wrap_request(req)
end
end
end

Expand Down
16 changes: 15 additions & 1 deletion spec/lib/http/retriable/performer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,24 @@ def response(**options)
expect(counter_spy).to eq 5
end
end

describe "when client has other features enabled" do
let(:client) { HTTP.retriable.use(:dummy) }

it "retries them as well" do
expect do
perform({ retry_statuses: [200], tries: 5 }, client) do
response
end
end.to raise_error(HTTP::OutOfRetriesError)

expect(DummyFeature.instance.wrap_request_called_with.length).to eq(4)
end
end
end

describe "connection closing" do
let(:client) { double(:client) }
let(:client) { double(:client, default_options: double(:options, features: {})) }

it "does not close the connection if we get a propper response" do
expect(client).not_to receive(:close)
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
require "rspec/memory"
require "support/capture_warning"
require "support/fakeio"
require "support/dummy_feature"

# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
Expand Down
51 changes: 51 additions & 0 deletions spec/support/dummy_feature.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# frozen_string_literal: true

class DummyFeature < HTTP::Feature
class << self
def instance
@instance ||=
begin
i = allocate
i.send(:initialize)
i
end
end

def new
instance
end
end

def initialize
super
reset!
end

attr_reader :wrap_request_called_with, :wrap_response_called_with, :on_error_called_with

def wrap_request(request)
@wrap_request_called_with << request
end

def wrap_response(response)
@wrap_response_called_with << response
end

def on_error(request, error)
@on_error_called_with << [request, error]
end

def reset!
@wrap_request_called_with = []
@wrap_response_called_with = []
@on_error_called_with = []
end

HTTP::Options.register_feature(:dummy, self)
end

RSpec.configure do |config|
config.before do
DummyFeature.instance.reset!
end
end
Loading