Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/bitbucket/connection_spec.rb')
-rw-r--r--spec/lib/bitbucket/connection_spec.rb45
1 files changed, 45 insertions, 0 deletions
diff --git a/spec/lib/bitbucket/connection_spec.rb b/spec/lib/bitbucket/connection_spec.rb
index 2b35a37558c..6cf010f2eed 100644
--- a/spec/lib/bitbucket/connection_spec.rb
+++ b/spec/lib/bitbucket/connection_spec.rb
@@ -19,6 +19,10 @@ RSpec.describe Bitbucket::Connection, feature_category: :integrations do
token_url: OmniAuth::Strategies::Bitbucket.default_options[:client_options]['token_url']
}
+ expect_next_instance_of(described_class) do |instance|
+ expect(instance).to receive(:retry_with_exponential_backoff).and_call_original
+ end
+
expect(OAuth2::Client)
.to receive(:new)
.with(anything, anything, expected_client_options)
@@ -31,6 +35,47 @@ RSpec.describe Bitbucket::Connection, feature_category: :integrations do
connection.get('/users')
end
+
+ context 'when the API returns an error' do
+ before do
+ allow_next_instance_of(OAuth2::AccessToken) do |instance|
+ allow(instance).to receive(:get).and_raise(OAuth2::Error, 'some error')
+ end
+
+ stub_const('Bitbucket::ExponentialBackoff::INITIAL_DELAY', 0.0)
+ allow(Random).to receive(:rand).and_return(0.001)
+ end
+
+ it 'logs the retries and raises an error if it does not succeed on retry' do
+ expect(Gitlab::BitbucketImport::Logger).to receive(:info)
+ .with(message: 'Retrying in 0.0 seconds due to some error')
+ .twice
+
+ connection = described_class.new({ token: token })
+
+ expect { connection.get('/users') }.to raise_error(Bitbucket::ExponentialBackoff::RateLimitError)
+ end
+ end
+
+ context 'when the bitbucket_importer_exponential_backoff feature flag is disabled' do
+ before do
+ stub_feature_flags(bitbucket_importer_exponential_backoff: false)
+ end
+
+ it 'does not run with exponential backoff' do
+ expect_next_instance_of(described_class) do |instance|
+ expect(instance).not_to receive(:retry_with_exponential_backoff).and_call_original
+ end
+
+ expect_next_instance_of(OAuth2::AccessToken) do |instance|
+ expect(instance).to receive(:get).and_return(double(parsed: true))
+ end
+
+ connection = described_class.new({ token: token })
+
+ connection.get('/users')
+ end
+ end
end
describe '#expired?' do