diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 11:43:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 11:43:02 +0300 |
commit | d9ab72d6080f594d0b3cae15f14b3ef2c6c638cb (patch) | |
tree | 2341ef426af70ad1e289c38036737e04b0aa5007 /spec/lib/bulk_imports/network_error_spec.rb | |
parent | d6e514dd13db8947884cd58fe2a9c2a063400a9b (diff) |
Add latest changes from gitlab-org/gitlab@14-4-stable-eev14.4.0-rc42
Diffstat (limited to 'spec/lib/bulk_imports/network_error_spec.rb')
-rw-r--r-- | spec/lib/bulk_imports/network_error_spec.rb | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/spec/lib/bulk_imports/network_error_spec.rb b/spec/lib/bulk_imports/network_error_spec.rb new file mode 100644 index 00000000000..11f555fee09 --- /dev/null +++ b/spec/lib/bulk_imports/network_error_spec.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe BulkImports::NetworkError, :clean_gitlab_redis_cache do + let(:tracker) { double(id: 1, stage: 2, entity: double(id: 3)) } + + describe '.new' do + it 'requires either a message or a HTTP response' do + expect { described_class.new } + .to raise_error(ArgumentError, 'message or response required') + end + end + + describe '#retriable?' do + it 'returns true for MAX_RETRIABLE_COUNT times when cause if one of RETRIABLE_EXCEPTIONS' do + raise described_class::RETRIABLE_EXCEPTIONS.sample + rescue StandardError => cause + begin + raise described_class, cause + rescue StandardError => exception + described_class::MAX_RETRIABLE_COUNT.times do + expect(exception.retriable?(tracker)).to eq(true) + end + + expect(exception.retriable?(tracker)).to eq(false) + end + end + + it 'returns true for MAX_RETRIABLE_COUNT times when response is one of RETRIABLE_CODES' do + exception = described_class.new(response: double(code: 429)) + + described_class::MAX_RETRIABLE_COUNT.times do + expect(exception.retriable?(tracker)).to eq(true) + end + + expect(exception.retriable?(tracker)).to eq(false) + end + + it 'returns false for other exceptions' do + raise StandardError + rescue StandardError => cause + begin + raise described_class, cause + rescue StandardError => exception + expect(exception.retriable?(tracker)).to eq(false) + end + end + end + + describe '#retry_delay' do + it 'returns the default value when there is not a rate limit error' do + exception = described_class.new('foo') + + expect(exception.retry_delay).to eq(described_class::DEFAULT_RETRY_DELAY_SECONDS.seconds) + end + + context 'when the exception is a rate limit error' do + it 'returns the "Retry-After"' do + exception = described_class.new(response: double(code: 429, headers: { 'Retry-After' => 20 })) + + expect(exception.retry_delay).to eq(20.seconds) + end + + it 'returns the default value when there is no "Retry-After" header' do + exception = described_class.new(response: double(code: 429, headers: {})) + + expect(exception.retry_delay).to eq(described_class::DEFAULT_RETRY_DELAY_SECONDS.seconds) + end + end + end +end |