diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-27 15:09:41 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-27 15:09:41 +0300 |
commit | 45999bfdec535b959f46fa4ed8f761bb3eadfed4 (patch) | |
tree | 12dda4fdec530172f3d21da4cc667dd73c9df133 /spec | |
parent | 39fa1b598749be0aad699032bbf31450b3ff0098 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
4 files changed, 85 insertions, 9 deletions
diff --git a/spec/lib/gitlab/database/migration_helpers_spec.rb b/spec/lib/gitlab/database/migration_helpers_spec.rb index 3a0148615b9..d450d2953cc 100644 --- a/spec/lib/gitlab/database/migration_helpers_spec.rb +++ b/spec/lib/gitlab/database/migration_helpers_spec.rb @@ -1365,6 +1365,14 @@ describe Gitlab::Database::MigrationHelpers do end end + it 'returns the final expected delay' do + Sidekiq::Testing.fake! do + final_delay = model.queue_background_migration_jobs_by_range_at_intervals(User, 'FooJob', 10.minutes, batch_size: 2) + + expect(final_delay.to_f).to eq(20.minutes.to_f) + end + end + context 'with batch_size option' do it 'queues jobs correctly' do Sidekiq::Testing.fake! do @@ -1389,12 +1397,25 @@ describe Gitlab::Database::MigrationHelpers do end end - context 'with other_arguments option' do + context 'with other_job_arguments option' do + it 'queues jobs correctly' do + Sidekiq::Testing.fake! do + model.queue_background_migration_jobs_by_range_at_intervals(User, 'FooJob', 10.minutes, other_job_arguments: [1, 2]) + + expect(BackgroundMigrationWorker.jobs[0]['args']).to eq(['FooJob', [id1, id3, 1, 2]]) + expect(BackgroundMigrationWorker.jobs[0]['at']).to eq(10.minutes.from_now.to_f) + end + end + end + + context 'with initial_delay option' do it 'queues jobs correctly' do - model.queue_background_migration_jobs_by_range_at_intervals(User, 'FooJob', 10.minutes, other_arguments: [1, 2]) + Sidekiq::Testing.fake! do + model.queue_background_migration_jobs_by_range_at_intervals(User, 'FooJob', 10.minutes, other_job_arguments: [1, 2], initial_delay: 10.minutes) - expect(BackgroundMigrationWorker.jobs[0]['args']).to eq(['FooJob', [id1, id3, 1, 2]]) - expect(BackgroundMigrationWorker.jobs[0]['at']).to eq(10.minutes.from_now.to_f) + expect(BackgroundMigrationWorker.jobs[0]['args']).to eq(['FooJob', [id1, id3, 1, 2]]) + expect(BackgroundMigrationWorker.jobs[0]['at']).to eq(20.minutes.from_now.to_f) + end end end end diff --git a/spec/migrations/cleanup_optimistic_locking_nulls_pt2_fixed_spec.rb b/spec/migrations/cleanup_optimistic_locking_nulls_pt2_fixed_spec.rb new file mode 100644 index 00000000000..2f8237c1c1c --- /dev/null +++ b/spec/migrations/cleanup_optimistic_locking_nulls_pt2_fixed_spec.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20200427064130_cleanup_optimistic_locking_nulls_pt2_fixed.rb') + +describe CleanupOptimisticLockingNullsPt2Fixed, :migration do + TABLES = %w(ci_stages ci_builds ci_pipelines).freeze + TABLES.each do |table| + let(table.to_sym) { table(table.to_sym) } + end + let(:tables) { TABLES.map { |t| method(t.to_sym).call } } + + before do + # Create necessary rows + ci_stages.create! + ci_builds.create! + ci_pipelines.create! + + # Nullify `lock_version` column for all rows + # Needs to be done with a SQL fragment, otherwise Rails will coerce it to 0 + tables.each do |table| + table.update_all('lock_version = NULL') + end + end + + it 'correctly migrates nullified lock_version column', :sidekiq_might_not_need_inline do + tables.each do |table| + expect(table.where(lock_version: nil).count).to eq(1) + end + + tables.each do |table| + expect(table.where(lock_version: 0).count).to eq(0) + end + + migrate! + + tables.each do |table| + expect(table.where(lock_version: nil).count).to eq(0) + end + + tables.each do |table| + expect(table.where(lock_version: 0).count).to eq(1) + end + end +end diff --git a/spec/services/users/destroy_service_spec.rb b/spec/services/users/destroy_service_spec.rb index 216d9170274..6e4b293286b 100644 --- a/spec/services/users/destroy_service_spec.rb +++ b/spec/services/users/destroy_service_spec.rb @@ -42,13 +42,11 @@ describe Users::DestroyService do it 'calls the bulk snippet destroy service for the user personal snippets' do repo1 = create(:personal_snippet, :repository, author: user).snippet_repository - repo2 = create(:project_snippet, :repository, author: user).snippet_repository - repo3 = create(:project_snippet, :repository, project: project, author: user).snippet_repository + repo2 = create(:project_snippet, :repository, project: project, author: user).snippet_repository aggregate_failures do expect(gitlab_shell.repository_exists?(repo1.shard_name, repo1.disk_path + '.git')).to be_truthy expect(gitlab_shell.repository_exists?(repo2.shard_name, repo2.disk_path + '.git')).to be_truthy - expect(gitlab_shell.repository_exists?(repo3.shard_name, repo3.disk_path + '.git')).to be_truthy end # Call made when destroying user personal projects @@ -59,17 +57,23 @@ describe Users::DestroyService do # project snippets where projects are not user personal # ones expect(Snippets::BulkDestroyService).to receive(:new) - .with(admin, user.snippets).and_call_original + .with(admin, user.snippets.only_personal_snippets).and_call_original service.execute(user) aggregate_failures do expect(gitlab_shell.repository_exists?(repo1.shard_name, repo1.disk_path + '.git')).to be_falsey expect(gitlab_shell.repository_exists?(repo2.shard_name, repo2.disk_path + '.git')).to be_falsey - expect(gitlab_shell.repository_exists?(repo3.shard_name, repo3.disk_path + '.git')).to be_falsey end end + it 'does not delete project snippets that the user is the author of' do + repo = create(:project_snippet, :repository, author: user).snippet_repository + service.execute(user) + expect(gitlab_shell.repository_exists?(repo.shard_name, repo.disk_path + '.git')).to be_truthy + expect(User.ghost.snippets).to include(repo.snippet) + end + context 'when an error is raised deleting snippets' do it 'does not delete user' do snippet = create(:personal_snippet, :repository, author: user) diff --git a/spec/services/users/migrate_to_ghost_user_service_spec.rb b/spec/services/users/migrate_to_ghost_user_service_spec.rb index 40206775aed..a7d7c16a66f 100644 --- a/spec/services/users/migrate_to_ghost_user_service_spec.rb +++ b/spec/services/users/migrate_to_ghost_user_service_spec.rb @@ -78,6 +78,12 @@ describe Users::MigrateToGhostUserService do end end + context 'snippets' do + include_examples "migrating a deleted user's associated records to the ghost user", Snippet do + let(:created_record) { create(:snippet, project: project, author: user) } + end + end + context "when record migration fails with a rollback exception" do before do expect_any_instance_of(ActiveRecord::Associations::CollectionProxy) |