Commit f8d509f8 authored by Andy Soiron's avatar Andy Soiron Committed by Jan Provaznik

Remove default value for udpate_sequence_id

In order to make the workers idempotent we need to make sure
udpate_sequence_id stays the same.
parent b0e75592
......@@ -889,7 +889,7 @@
:urgency: :low
:resource_boundary: :unknown
:weight: 1
:idempotent:
:idempotent: true
:tags: []
- :name: jira_connect:jira_connect_sync_builds
:feature_category: :integrations
......@@ -913,7 +913,7 @@
:urgency: :low
:resource_boundary: :unknown
:weight: 1
:idempotent:
:idempotent: true
:tags: []
- :name: jira_connect:jira_connect_sync_project
:feature_category: :integrations
......
......@@ -8,8 +8,9 @@ module JiraConnect
feature_category :integrations
loggable_arguments 1, 2
worker_has_external_dependencies!
idempotent!
def perform(project_id, branch_name, commit_shas, update_sequence_id = nil)
def perform(project_id, branch_name, commit_shas, update_sequence_id)
project = Project.find_by_id(project_id)
return unless project
......
......@@ -6,10 +6,11 @@ module JiraConnect
queue_namespace :jira_connect
feature_category :integrations
idempotent!
worker_has_external_dependencies!
def perform(merge_request_id, update_sequence_id = nil)
def perform(merge_request_id, update_sequence_id)
merge_request = MergeRequest.find_by_id(merge_request_id)
return unless merge_request && merge_request.project
......
---
title: Fix Jira MR status not syncing by making workers idempotent
merge_request: 51006
author:
type: fixed
......@@ -13,82 +13,67 @@ RSpec.describe JiraConnect::SyncBranchWorker do
let(:project_id) { project.id }
let(:branch_name) { 'master' }
let(:commit_shas) { %w(b83d6e3 5a62481) }
subject { described_class.new.perform(project_id, branch_name, commit_shas) }
let(:update_sequence_id) { 1 }
def expect_jira_sync_service_execute(args)
expect_next_instance_of(JiraConnect::SyncService) do |instance|
expect(instance).to receive(:execute).with(args.merge(update_sequence_id: nil))
expect_next_instances_of(JiraConnect::SyncService, IdempotentWorkerHelper::WORKER_EXEC_TIMES) do |instance|
expect(instance).to receive(:execute).with(args)
end
end
it 'calls JiraConnect::SyncService#execute' do
expect_jira_sync_service_execute(
branches: [instance_of(Gitlab::Git::Branch)],
commits: project.commits_by(oids: commit_shas)
)
subject
end
it_behaves_like 'an idempotent worker' do
let(:job_args) { [project_id, branch_name, commit_shas, update_sequence_id] }
context 'without branch name' do
let(:branch_name) { nil }
it 'calls JiraConnect::SyncService#execute' do
expect_jira_sync_service_execute(
branches: nil,
commits: project.commits_by(oids: commit_shas)
)
subject
before do
stub_request(:post, 'https://sample.atlassian.net/rest/devinfo/0.10/bulk').to_return(status: 200, body: '', headers: {})
end
end
context 'without commits' do
let(:commit_shas) { nil }
it 'calls JiraConnect::SyncService#execute' do
expect_jira_sync_service_execute(
branches: [instance_of(Gitlab::Git::Branch)],
commits: nil
commits: project.commits_by(oids: commit_shas),
update_sequence_id: update_sequence_id
)
subject
end
end
context 'when project no longer exists' do
let(:project_id) { non_existing_record_id }
context 'without branch name' do
let(:branch_name) { nil }
it 'does not call JiraConnect::SyncService' do
expect(JiraConnect::SyncService).not_to receive(:new)
it 'calls JiraConnect::SyncService#execute' do
expect_jira_sync_service_execute(
branches: nil,
commits: project.commits_by(oids: commit_shas),
update_sequence_id: update_sequence_id
)
subject
subject
end
end
end
context 'with update_sequence_id' do
let(:update_sequence_id) { 1 }
let(:request_path) { '/rest/devinfo/0.10/bulk' }
let(:request_body) do
{
repositories: [
Atlassian::JiraConnect::Serializers::RepositoryEntity.represent(
project,
commits: project.commits_by(oids: commit_shas),
branches: [project.repository.find_branch(branch_name)],
update_sequence_id: update_sequence_id
)
]
}
context 'without commits' do
let(:commit_shas) { nil }
it 'calls JiraConnect::SyncService#execute' do
expect_jira_sync_service_execute(
branches: [instance_of(Gitlab::Git::Branch)],
commits: nil,
update_sequence_id: update_sequence_id
)
subject
end
end
subject { described_class.new.perform(project_id, branch_name, commit_shas, update_sequence_id) }
context 'when project no longer exists' do
let(:project_id) { non_existing_record_id }
it 'sends the reqeust with custom update_sequence_id' do
expect_next(Atlassian::JiraConnect::Client).to receive(:post).with(request_path, request_body)
it 'does not call JiraConnect::SyncService' do
expect(JiraConnect::SyncService).not_to receive(:new)
subject
subject
end
end
end
end
......
......@@ -12,48 +12,31 @@ RSpec.describe JiraConnect::SyncMergeRequestWorker do
let_it_be(:merge_request) { create(:merge_request, source_project: project) }
let(:merge_request_id) { merge_request.id }
let(:update_sequence_id) { 1 }
subject { described_class.new.perform(merge_request_id) }
it_behaves_like 'an idempotent worker' do
let(:job_args) { [merge_request_id, update_sequence_id] }
it 'calls JiraConnect::SyncService#execute' do
expect_next_instance_of(JiraConnect::SyncService) do |service|
expect(service).to receive(:execute).with(merge_requests: [merge_request], update_sequence_id: nil)
before do
stub_request(:post, 'https://sample.atlassian.net/rest/devinfo/0.10/bulk').to_return(status: 200, body: '', headers: {})
end
subject
end
context 'when MR no longer exists' do
let(:merge_request_id) { non_existing_record_id }
it 'does not call JiraConnect::SyncService' do
expect(JiraConnect::SyncService).not_to receive(:new)
it 'calls JiraConnect::SyncService#execute' do
expect_next_instances_of(JiraConnect::SyncService, IdempotentWorkerHelper::WORKER_EXEC_TIMES) do |service|
expect(service).to receive(:execute).with(merge_requests: [merge_request], update_sequence_id: update_sequence_id)
end
subject
end
end
context 'with update_sequence_id' do
let(:update_sequence_id) { 1 }
let(:request_path) { '/rest/devinfo/0.10/bulk' }
let(:request_body) do
{
repositories: [
Atlassian::JiraConnect::Serializers::RepositoryEntity.represent(
project,
merge_requests: [merge_request],
update_sequence_id: update_sequence_id
)
]
}
end
subject { described_class.new.perform(merge_request_id, update_sequence_id) }
context 'when MR no longer exists' do
let(:merge_request_id) { non_existing_record_id }
it 'sends the request with custom update_sequence_id' do
expect_next(Atlassian::JiraConnect::Client).to receive(:post).with(request_path, request_body)
it 'does not call JiraConnect::SyncService' do
expect(JiraConnect::SyncService).not_to receive(:new)
subject
subject
end
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment