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,19 +13,26 @@ 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_behaves_like 'an idempotent worker' do
let(:job_args) { [project_id, branch_name, commit_shas, update_sequence_id] }
before do
stub_request(:post, 'https://sample.atlassian.net/rest/devinfo/0.10/bulk').to_return(status: 200, body: '', headers: {})
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)
commits: project.commits_by(oids: commit_shas),
update_sequence_id: update_sequence_id
)
subject
......@@ -37,7 +44,8 @@ RSpec.describe JiraConnect::SyncBranchWorker do
it 'calls JiraConnect::SyncService#execute' do
expect_jira_sync_service_execute(
branches: nil,
commits: project.commits_by(oids: commit_shas)
commits: project.commits_by(oids: commit_shas),
update_sequence_id: update_sequence_id
)
subject
......@@ -50,7 +58,8 @@ RSpec.describe JiraConnect::SyncBranchWorker do
it 'calls JiraConnect::SyncService#execute' do
expect_jira_sync_service_execute(
branches: [instance_of(Gitlab::Git::Branch)],
commits: nil
commits: nil,
update_sequence_id: update_sequence_id
)
subject
......@@ -66,30 +75,6 @@ RSpec.describe JiraConnect::SyncBranchWorker do
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,
commits: project.commits_by(oids: commit_shas),
branches: [project.repository.find_branch(branch_name)],
update_sequence_id: update_sequence_id
)
]
}
end
subject { described_class.new.perform(project_id, branch_name, commit_shas, update_sequence_id) }
it 'sends the reqeust with custom update_sequence_id' do
expect_next(Atlassian::JiraConnect::Client).to receive(:post).with(request_path, request_body)
subject
end
end
end
end
......@@ -12,12 +12,18 @@ 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 }
it_behaves_like 'an idempotent worker' do
let(:job_args) { [merge_request_id, update_sequence_id] }
subject { described_class.new.perform(merge_request_id) }
before do
stub_request(:post, 'https://sample.atlassian.net/rest/devinfo/0.10/bulk').to_return(status: 200, body: '', headers: {})
end
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)
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
......@@ -32,29 +38,6 @@ RSpec.describe JiraConnect::SyncMergeRequestWorker do
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) }
it 'sends the request with custom update_sequence_id' do
expect_next(Atlassian::JiraConnect::Client).to receive(:post).with(request_path, request_body)
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