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:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-08-13 12:09:58 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-08-13 12:09:58 +0300
commitda12067d6bb2603f40d2de107df70e2ff03630e8 (patch)
tree7d5fcdce8e53a4f491d9a6a81826ffef3589cf83 /spec/workers/jira_connect
parente9626c2383e1bbf325a302bb840891c3c7b8cb07 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers/jira_connect')
-rw-r--r--spec/workers/jira_connect/forward_event_worker_spec.rb22
-rw-r--r--spec/workers/jira_connect/retry_request_worker_spec.rb45
2 files changed, 52 insertions, 15 deletions
diff --git a/spec/workers/jira_connect/forward_event_worker_spec.rb b/spec/workers/jira_connect/forward_event_worker_spec.rb
index adfc071779a..7de9952a1da 100644
--- a/spec/workers/jira_connect/forward_event_worker_spec.rb
+++ b/spec/workers/jira_connect/forward_event_worker_spec.rb
@@ -15,23 +15,23 @@ RSpec.describe JiraConnect::ForwardEventWorker do
let(:client_key) { '123' }
let(:shared_secret) { '123' }
- subject { described_class.new.perform(jira_connect_installation.id, base_path, event_path) }
+ subject(:perform) { described_class.new.perform(jira_connect_installation.id, base_path, event_path) }
- it 'forwards the event including the auth header and deletes the installation' do
+ it 'forwards the event and deletes the installation' do
stub_request(:post, event_url)
expect(Atlassian::Jwt).to receive(:create_query_string_hash).with(event_url, 'POST', base_url).and_return('some_qsh')
expect(Atlassian::Jwt).to receive(:encode).with({ iss: client_key, qsh: 'some_qsh' }, shared_secret).and_return('auth_token')
- expect { subject }.to change(JiraConnectInstallation, :count).by(-1)
+ expect(JiraConnect::RetryRequestWorker).to receive(:perform_async).with(event_url, 'auth_token')
- expect(WebMock).to have_requested(:post, event_url).with(headers: { 'Authorization' => 'JWT auth_token' })
+ expect { perform }.to change(JiraConnectInstallation, :count).by(-1)
end
context 'when installation does not exist' do
let(:jira_connect_installation) { instance_double(JiraConnectInstallation, id: -1) }
it 'does nothing' do
- expect { subject }.not_to change(JiraConnectInstallation, :count)
+ expect { perform }.not_to change(JiraConnectInstallation, :count)
end
end
@@ -39,17 +39,9 @@ RSpec.describe JiraConnect::ForwardEventWorker do
let!(:jira_connect_installation) { create(:jira_connect_installation) }
it 'forwards the event including the auth header' do
- expect { subject }.to change(JiraConnectInstallation, :count).by(-1)
+ expect { perform }.to change(JiraConnectInstallation, :count).by(-1)
- expect(WebMock).not_to have_requested(:post, '*')
- end
- end
-
- context 'when it fails to forward the event' do
- it 'still deletes the installation' do
- allow(Gitlab::HTTP).to receive(:post).and_raise(StandardError)
-
- expect { subject }.to raise_error(StandardError).and change(JiraConnectInstallation, :count).by(-1)
+ expect(JiraConnect::RetryRequestWorker).not_to receive(:perform_async)
end
end
end
diff --git a/spec/workers/jira_connect/retry_request_worker_spec.rb b/spec/workers/jira_connect/retry_request_worker_spec.rb
new file mode 100644
index 00000000000..7a93e5fe41d
--- /dev/null
+++ b/spec/workers/jira_connect/retry_request_worker_spec.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe JiraConnect::RetryRequestWorker do
+ describe '#perform' do
+ let(:jwt) { 'some-jwt' }
+ let(:event_url) { 'https://example.com/somewhere' }
+ let(:attempts) { 3 }
+
+ subject(:perform) { described_class.new.perform(event_url, jwt, attempts) }
+
+ it 'sends the request, with the appropriate headers' do
+ expect(JiraConnect::RetryRequestWorker).not_to receive(:perform_in)
+
+ stub_request(:post, event_url)
+
+ perform
+
+ expect(WebMock).to have_requested(:post, event_url).with(headers: { 'Authorization' => 'JWT some-jwt' })
+ end
+
+ context 'when the proxied request fails' do
+ before do
+ stub_request(:post, event_url).to_return(status: 500, body: '', headers: {})
+ end
+
+ it 'arranges to retry the request' do
+ expect(JiraConnect::RetryRequestWorker).to receive(:perform_in).with(1.hour, event_url, jwt, attempts - 1)
+
+ perform
+ end
+
+ context 'when there are no more attempts left' do
+ let(:attempts) { 0 }
+
+ it 'does not retry' do
+ expect(JiraConnect::RetryRequestWorker).not_to receive(:perform_in)
+
+ perform
+ end
+ end
+ end
+ end
+end