diff options
author | Stan Hu <stanhu@gmail.com> | 2018-08-24 22:58:50 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-08-26 17:13:36 +0300 |
commit | 09cdd7dca0916f9edec3e531c6787a6050bc295f (patch) | |
tree | 42e5e1f78d11a85ce789cd883beb6a9302322c71 /spec/lib/gitlab/import | |
parent | 452fd703f322370e6bf12a4f243e258db7e278f5 (diff) |
Bitbucket Server importer: Eliminate most idle-in-transaction issues
Just like with the GitHub importer, the Bitbucket Server importer can hit the
default 60 s idle-in-transaction timeouts if it takes too long to create the
merge request. We solve this by using the same approach as the GitHub importer:
1. Bypass all validation and hooks in creating a merge request
2. Insert the Git data in a separate transaction
Part of #50021
Diffstat (limited to 'spec/lib/gitlab/import')
-rw-r--r-- | spec/lib/gitlab/import/merge_request_creator_spec.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/spec/lib/gitlab/import/merge_request_creator_spec.rb b/spec/lib/gitlab/import/merge_request_creator_spec.rb new file mode 100644 index 00000000000..cd3359da341 --- /dev/null +++ b/spec/lib/gitlab/import/merge_request_creator_spec.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Import::MergeRequestCreator do + let(:project) { create(:project, :repository) } + + subject { described_class.new(project) } + + describe '#execute' do + context 'merge request already exists' do + let(:merge_request) { create(:merge_request, target_project: project, source_project: project) } + let(:commits) { merge_request.merge_request_diffs.first.commits } + let(:attributes) { HashWithIndifferentAccess.new(merge_request.attributes) } + + it 'updates the data' do + commits_count = commits.count + merge_request.merge_request_diffs.destroy_all # rubocop: disable DestroyAll + + expect(merge_request.merge_request_diffs.count).to eq(0) + + subject.execute(attributes) + + expect(merge_request.reload.merge_request_diffs.count).to eq(1) + expect(merge_request.reload.merge_request_diffs.first.commits.count).to eq(commits_count) + end + end + + context 'new merge request' do + let(:merge_request) { build(:merge_request, target_project: project, source_project: project) } + let(:attributes) { HashWithIndifferentAccess.new(merge_request.attributes) } + + it 'creates a new merge request' do + attributes.delete(:id) + + expect { subject.execute(attributes) }.to change { MergeRequest.count }.by(1) + + new_mr = MergeRequest.last + expect(new_mr.merge_request_diffs.count).to eq(1) + end + end + end +end |