Welcome to mirror list, hosted at ThFree Co, Russian Federation.

reschedule_incident_work_item_type_id_backfill_spec.rb « migrations « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cb8773e9a9f927f94e12d2cf5746ce7570331bca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# frozen_string_literal: true

require 'spec_helper'
require_migration!

RSpec.describe RescheduleIncidentWorkItemTypeIdBackfill, :migration, feature_category: :team_planning do
  include MigrationHelpers::WorkItemTypesHelper

  let!(:migration) { described_class::MIGRATION }
  let!(:interval) { 2.minutes }
  let!(:incident_type_enum) { 1 }
  let!(:issue_type_enum) { 0 }
  let!(:incident_work_item_type) do
    table(:work_item_types).find_by!(namespace_id: nil, base_type: incident_type_enum)
  end

  let!(:issue_work_item_type) do
    table(:work_item_types).find_by!(namespace_id: nil, base_type: issue_type_enum)
  end

  describe '#up' do
    let!(:existing_incident_migration) { create_backfill_migration(incident_type_enum, incident_work_item_type.id) }
    let!(:existing_issue_migration) { create_backfill_migration(issue_type_enum, issue_work_item_type.id) }

    it 'correctly reschedules background migration only for incidents' do
      migrate!

      migration_ids = table(:batched_background_migrations).pluck(:id)

      expect(migration).to have_scheduled_batched_migration(
        table_name: :issues,
        column_name: :id,
        job_arguments: [incident_type_enum, incident_work_item_type.id],
        interval: interval,
        batch_size: described_class::BATCH_SIZE,
        max_batch_size: described_class::MAX_BATCH_SIZE,
        sub_batch_size: described_class::SUB_BATCH_SIZE
      )
      expect(migration_ids.count).to eq(2)
      expect(migration_ids).not_to include(existing_incident_migration.id)
      expect(migration_ids).to include(existing_issue_migration.id)
    end

    it "doesn't fail if work item types don't exist on the DB" do
      table(:work_item_types).delete_all

      migrate!

      # Since migration specs run outside of a transaction, we need to make
      # sure we recreate default types since this spec deletes them all
      reset_work_item_types
    end
  end

  def create_backfill_migration(base_type, type_id)
    table(:batched_background_migrations).create!(
      job_class_name: migration,
      table_name: :issues,
      column_name: :id,
      job_arguments: [base_type, type_id],
      interval: 2.minutes,
      min_value: 1,
      max_value: 2,
      batch_size: 1000,
      sub_batch_size: 200,
      gitlab_schema: :gitlab_main,
      status: 3
    )
  end
end