2021-05-19 05:10:19 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe "Admin > Admin sees background migrations" do
|
|
|
|
let_it_be(:admin) { create(:admin) }
|
|
|
|
|
2022-04-02 02:09:49 -04:00
|
|
|
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') }
|
2021-05-19 05:10:19 -04:00
|
|
|
|
|
|
|
before_all do
|
2022-02-03 10:12:41 -05:00
|
|
|
create(:batched_background_migration_job, :failed, batched_migration: failed_migration, batch_size: 10, min_value: 6, max_value: 15, attempts: 3)
|
2021-05-19 05:10:19 -04:00
|
|
|
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
|
|
|
|
|
2022-04-25 20:08:40 -04:00
|
|
|
it 'can click on a specific migration' do
|
|
|
|
visit admin_background_migrations_path
|
|
|
|
|
|
|
|
within '#content-body' do
|
|
|
|
tab = find_link active_migration.job_class_name
|
|
|
|
tab.click
|
|
|
|
|
|
|
|
expect(page).to have_current_path admin_background_migration_path(active_migration)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-08 08:08:30 -04:00
|
|
|
it 'can view queued migrations and pause and resume them' do
|
2021-05-19 05:10:19 -04:00
|
|
|
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%')
|
2021-07-08 08:08:30 -04: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')
|
2021-05-19 05:10:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-08-23 05:10:23 -04:00
|
|
|
context 'when there are failed migrations' do
|
|
|
|
before do
|
|
|
|
allow_next_instance_of(Gitlab::BackgroundMigration::BatchingStrategies::PrimaryKeyBatchingStrategy) do |batch_class|
|
2022-03-10 07:07:07 -05:00
|
|
|
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])
|
2021-08-23 05:10:23 -04:00
|
|
|
end
|
|
|
|
end
|
2021-05-19 05:10:19 -04:00
|
|
|
|
2021-08-23 05:10:23 -04:00
|
|
|
it 'can view and retry them' do
|
|
|
|
visit admin_background_migrations_path
|
2021-05-19 05:10:19 -04:00
|
|
|
|
2021-08-23 05:10:23 -04:00
|
|
|
within '#content-body' do
|
|
|
|
tab = find_link 'Failed'
|
|
|
|
tab.click
|
2021-05-19 05:10:19 -04:00
|
|
|
|
2021-08-23 05:10:23 -04:00
|
|
|
expect(page).to have_current_path(admin_background_migrations_path(tab: 'failed'))
|
2022-02-02 13:15:35 -05:00
|
|
|
expect(tab[:class]).to include('gl-tab-nav-item-active')
|
2021-08-23 05:10:23 -04:00
|
|
|
|
|
|
|
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%')
|
2022-04-02 02:09:49 -04:00
|
|
|
expect(page).to have_content(failed_migration.status_name.to_s)
|
2021-05-19 05:10:19 -04:00
|
|
|
|
2021-08-23 05:10:23 -04:00
|
|
|
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
|
2021-05-19 05:10:19 -04:00
|
|
|
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'))
|
2022-02-02 13:15:35 -05:00
|
|
|
expect(tab[:class]).to include('gl-tab-nav-item-active')
|
2021-05-19 05:10:19 -04:00
|
|
|
|
|
|
|
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%')
|
2022-04-02 02:09:49 -04:00
|
|
|
expect(page).to have_content(finished_migration.status_name.to_s)
|
2021-05-19 05:10:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|