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/gitlab/github_import/client_spec.rb')
-rw-r--r--spec/lib/gitlab/github_import/client_spec.rb71
1 files changed, 71 insertions, 0 deletions
diff --git a/spec/lib/gitlab/github_import/client_spec.rb b/spec/lib/gitlab/github_import/client_spec.rb
index 194dfb228ee..c4d05e92633 100644
--- a/spec/lib/gitlab/github_import/client_spec.rb
+++ b/spec/lib/gitlab/github_import/client_spec.rb
@@ -221,6 +221,50 @@ RSpec.describe Gitlab::GithubImport::Client do
expect(client.with_rate_limit { 10 }).to eq(10)
end
+
+ context 'when Faraday error received from octokit', :aggregate_failures do
+ let(:error_class) { described_class::CLIENT_CONNECTION_ERROR }
+ let(:info_params) { { 'error.class': error_class } }
+ let(:block_to_rate_limit) { -> { client.pull_request('foo/bar', 999) } }
+
+ context 'when rate_limiting_enabled is true' do
+ it 'retries on error and succeeds' do
+ allow_retry
+
+ expect(client).to receive(:requests_remaining?).twice.and_return(true)
+ expect(Gitlab::Import::Logger).to receive(:info).with(hash_including(info_params)).once
+
+ expect(client.with_rate_limit(&block_to_rate_limit)).to be(true)
+ end
+
+ it 'retries and does not succeed' do
+ allow(client).to receive(:requests_remaining?).and_return(true)
+ allow(client.octokit).to receive(:pull_request).and_raise(error_class, 'execution expired')
+
+ expect { client.with_rate_limit(&block_to_rate_limit) }.to raise_error(error_class, 'execution expired')
+ end
+ end
+
+ context 'when rate_limiting_enabled is false' do
+ before do
+ allow(client).to receive(:rate_limiting_enabled?).and_return(false)
+ end
+
+ it 'retries on error and succeeds' do
+ allow_retry
+
+ expect(Gitlab::Import::Logger).to receive(:info).with(hash_including(info_params)).once
+
+ expect(client.with_rate_limit(&block_to_rate_limit)).to be(true)
+ end
+
+ it 'retries and does not succeed' do
+ allow(client.octokit).to receive(:pull_request).and_raise(error_class, 'execution expired')
+
+ expect { client.with_rate_limit(&block_to_rate_limit) }.to raise_error(error_class, 'execution expired')
+ end
+ end
+ end
end
describe '#requests_remaining?' do
@@ -505,6 +549,25 @@ RSpec.describe Gitlab::GithubImport::Client do
client.search_repos_by_name('test')
end
+
+ context 'when Faraday error received from octokit', :aggregate_failures do
+ let(:error_class) { described_class::CLIENT_CONNECTION_ERROR }
+ let(:info_params) { { 'error.class': error_class } }
+
+ it 'retries on error and succeeds' do
+ allow_retry(:search_repositories)
+
+ expect(Gitlab::Import::Logger).to receive(:info).with(hash_including(info_params)).once
+
+ expect(client.search_repos_by_name('test')).to be(true)
+ end
+
+ it 'retries and does not succeed' do
+ allow(client.octokit).to receive(:search_repositories).and_raise(error_class, 'execution expired')
+
+ expect { client.search_repos_by_name('test') }.to raise_error(error_class, 'execution expired')
+ end
+ end
end
describe '#search_query' do
@@ -531,4 +594,12 @@ RSpec.describe Gitlab::GithubImport::Client do
end
end
end
+
+ def allow_retry(method = :pull_request)
+ call_count = 0
+ allow(client.octokit).to receive(method) do
+ call_count += 1
+ call_count > 1 ? true : raise(described_class::CLIENT_CONNECTION_ERROR, 'execution expired')
+ end
+ end
end