Fixes #3583 - Zendesk-Import Connection reset by peer cancels import

This commit is contained in:
Mantas Masalskis 2021-08-11 13:11:14 +02:00 committed by Martin Gruner
parent 4770e80f03
commit f270b20b4f
2 changed files with 18 additions and 12 deletions

View file

@ -64,10 +64,7 @@ class Sequencer
end end
def retry_exception?(e) def retry_exception?(e)
return true if e.message.include?('execution expired') !(200..399).cover? e&.response&.status
status = e.response.status.to_s
status.match?(%r{^(4|5)\d\d$})
end end
def resource_collection def resource_collection

View file

@ -28,7 +28,7 @@ RSpec.shared_examples 'Sequencer::Unit::Import::Zendesk::SubSequence::Base' do
} }
end end
let(:collection_name) { described_class.name.demodulize.snakecase.to_sym } let(:collection_name) { described_class.name.demodulize.underscore.to_sym }
let(:client_collection) { double('ZendeskAPI::Collection') } let(:client_collection) { double('ZendeskAPI::Collection') }
let(:api_error_message) { 'Mock err msg' } let(:api_error_message) { 'Mock err msg' }
let(:api_error) { ZendeskAPI::Error::NetworkError.new(api_error_message, response_obj) } let(:api_error) { ZendeskAPI::Error::NetworkError.new(api_error_message, response_obj) }
@ -83,7 +83,7 @@ RSpec.shared_examples 'Sequencer::Unit::Import::Zendesk::SubSequence::Base' do
end end
end end
context 'when DNS resolution fails (getaddrinfo: nodename nor servname provided, or not known)' do shared_examples 'retries ten times, in 10s intervals' do
it 'retries ten times, in 10s intervals' do it 'retries ten times, in 10s intervals' do
expect(client_collection) expect(client_collection)
.to receive(:all!).exactly(11).times .to receive(:all!).exactly(11).times
@ -96,16 +96,25 @@ RSpec.shared_examples 'Sequencer::Unit::Import::Zendesk::SubSequence::Base' do
end end
end end
context 'when DNS resolution fails (getaddrinfo: nodename nor servname provided, or not known)' do
include_examples 'retries ten times, in 10s intervals'
end
context 'when execution timeout occurs' do context 'when execution timeout occurs' do
let(:api_error_message) { "execution expired -- get https://example.zendesk.com/api/v2/#{collection_name}" } let(:api_error_message) { "execution expired -- get https://example.zendesk.com/api/v2/#{collection_name}" }
it 'retries ten times, in 10s intervals' do include_examples 'retries ten times, in 10s intervals'
expect do
process(params) do |unit|
expect(unit).to receive(:sleep).with(10).exactly(10).times
end end
end.to raise_error(api_error)
context 'when reset by peer occurs' do
let(:api_error_message) { "Connection reset by peer - SSL_connect -- get https://example.zendesk.com/api/v2/#{collection_name}" }
# ssl error does not return 4xx or 5xx status code that triggers retry
let(:response_obj) do
double('Faraday::Response', method: :get, url: 'https://example.com', status: nil)
end end
include_examples 'retries ten times, in 10s intervals'
end end
end end
end end