diff options
author | Oswaldo Ferreira <oswaldo@gitlab.com> | 2019-05-21 18:14:22 -0300 |
---|---|---|
committer | Oswaldo Ferreira <oswaldo@gitlab.com> | 2019-06-20 11:48:30 -0300 |
commit | 3af348b6cf28ef1d9d3025f7012049132b57798c (patch) | |
tree | 540b724d6b711e3d2247dad5c371b54ec81ea610 /spec/migrations | |
parent | c6eb18ee0fe1b887438da87f25fc2f2a852dd393 (diff) | |
download | gitlab-ce-3af348b6cf28ef1d9d3025f7012049132b57798c.tar.gz |
Automatically update MR merge-ref along merge status
This couples the code that transitions the `MergeRequest#merge_status`
and refs/merge-requests/:iid/merge ref update.
In general, instead of directly telling `MergeToRefService` to update
the merge ref, we should rely on `MergeabilityCheckService` to keep
both the merge status and merge ref synced. Now, if the merge_status is
`can_be_merged` it means the merge-ref is also updated to the latest.
We've also updated the logic to be more systematic and less user-based.
Diffstat (limited to 'spec/migrations')
-rw-r--r-- | spec/migrations/enqueue_reset_merge_status_second_run_spec.rb | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/migrations/enqueue_reset_merge_status_second_run_spec.rb b/spec/migrations/enqueue_reset_merge_status_second_run_spec.rb new file mode 100644 index 00000000000..3c880c6f5fd --- /dev/null +++ b/spec/migrations/enqueue_reset_merge_status_second_run_spec.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20190620112608_enqueue_reset_merge_status_second_run.rb') + +describe EnqueueResetMergeStatusSecondRun, :migration, :sidekiq do + let(:namespaces) { table(:namespaces) } + let(:projects) { table(:projects) } + let(:namespace) { namespaces.create(name: 'gitlab', path: 'gitlab-org') } + let(:project) { projects.create(namespace_id: namespace.id, name: 'foo') } + let(:merge_requests) { table(:merge_requests) } + + def create_merge_request(id, extra_params = {}) + params = { + id: id, + target_project_id: project.id, + target_branch: 'master', + source_project_id: project.id, + source_branch: 'mr name', + title: "mr name#{id}" + }.merge(extra_params) + + merge_requests.create!(params) + end + + it 'correctly schedules background migrations' do + create_merge_request(1, state: 'opened', merge_status: 'can_be_merged') + create_merge_request(2, state: 'opened', merge_status: 'can_be_merged') + create_merge_request(3, state: 'opened', merge_status: 'can_be_merged') + create_merge_request(4, state: 'merged', merge_status: 'can_be_merged') + create_merge_request(5, state: 'opened', merge_status: 'unchecked') + + stub_const("#{described_class.name}::BATCH_SIZE", 2) + + Sidekiq::Testing.fake! do + Timecop.freeze do + migrate! + + expect(described_class::MIGRATION) + .to be_scheduled_delayed_migration(5.minutes, 1, 2) + + expect(described_class::MIGRATION) + .to be_scheduled_delayed_migration(10.minutes, 3, 4) + + expect(described_class::MIGRATION) + .to be_scheduled_delayed_migration(15.minutes, 5, 5) + + expect(BackgroundMigrationWorker.jobs.size).to eq(3) + end + end + end +end |