summaryrefslogtreecommitdiff
path: root/spec/features/admin/admin_sees_background_migrations_spec.rb
blob: 432721d63ad65d8e5ea1eda814746d9a9ea84e56 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe "Admin > Admin sees background migrations" do
  let_it_be(:admin) { create(:admin) }

  let_it_be(:active_migration) { create(:batched_background_migration, :active, table_name: 'active') }
  let_it_be(:failed_migration) { create(:batched_background_migration, :failed, table_name: 'failed', total_tuple_count: 100) }
  let_it_be(:finished_migration) { create(:batched_background_migration, :finished, table_name: 'finished') }

  before_all do
    create(:batched_background_migration_job, :failed, batched_migration: failed_migration, batch_size: 10, min_value: 6, max_value: 15, attempts: 3)
  end

  before do
    sign_in(admin)
    gitlab_enable_admin_mode_sign_in(admin)
  end

  it 'can navigate to background migrations' do
    visit admin_root_path

    within '.nav-sidebar' do
      link = find_link 'Background Migrations'

      link.click

      expect(page).to have_current_path(admin_background_migrations_path)
      expect(link).to have_ancestor(:css, 'li.active')
    end
  end

  it 'can view queued migrations and pause and resume them' do
    visit admin_background_migrations_path

    within '#content-body' do
      expect(page).to have_selector('tbody tr', count: 1)

      expect(page).to have_content(active_migration.job_class_name)
      expect(page).to have_content(active_migration.table_name)
      expect(page).to have_content('0.00%')
      expect(page).not_to have_content('Paused')
      expect(page).to have_content('Active')

      click_button('Pause')
      expect(page).not_to have_content('Active')
      expect(page).to have_content('Paused')

      click_button('Resume')
      expect(page).not_to have_content('Paused')
      expect(page).to have_content('Active')
    end
  end

  context 'when there are failed migrations' do
    before do
      allow_next_instance_of(Gitlab::BackgroundMigration::BatchingStrategies::PrimaryKeyBatchingStrategy) do |batch_class|
        allow(batch_class).to receive(:next_batch).with(
          anything,
          anything,
          batch_min_value: 6,
          batch_size: 5,
          job_arguments: failed_migration.job_arguments
        ).and_return([6, 10])
      end
    end

    it 'can view and retry them' do
      visit admin_background_migrations_path

      within '#content-body' do
        tab = find_link 'Failed'
        tab.click

        expect(page).to have_current_path(admin_background_migrations_path(tab: 'failed'))
        expect(tab[:class]).to include('gl-tab-nav-item-active')

        expect(page).to have_selector('tbody tr', count: 1)

        expect(page).to have_content(failed_migration.job_class_name)
        expect(page).to have_content(failed_migration.table_name)
        expect(page).to have_content('0.00%')
        expect(page).to have_content(failed_migration.status_name.to_s)

        click_button('Retry')
        expect(page).not_to have_content(failed_migration.job_class_name)
        expect(page).not_to have_content(failed_migration.table_name)
        expect(page).not_to have_content('0.00%')
      end
    end
  end

  it 'can view finished migrations' do
    visit admin_background_migrations_path

    within '#content-body' do
      tab = find_link 'Finished'
      tab.click

      expect(page).to have_current_path(admin_background_migrations_path(tab: 'finished'))
      expect(tab[:class]).to include('gl-tab-nav-item-active')

      expect(page).to have_selector('tbody tr', count: 1)

      expect(page).to have_content(finished_migration.job_class_name)
      expect(page).to have_content(finished_migration.table_name)
      expect(page).to have_content('100.00%')
      expect(page).to have_content(finished_migration.status_name.to_s)
    end
  end
end