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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-05-19 18:44:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-05-19 18:44:42 +0300
commit4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch)
tree5423a1c7516cffe36384133ade12572cf709398d /spec/tasks
parente570267f2f6b326480d284e0164a6464ba4081bc (diff)
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'spec/tasks')
-rw-r--r--spec/tasks/gitlab/db_rake_spec.rb42
-rw-r--r--spec/tasks/gitlab/sidekiq_rake_spec.rb53
2 files changed, 85 insertions, 10 deletions
diff --git a/spec/tasks/gitlab/db_rake_spec.rb b/spec/tasks/gitlab/db_rake_spec.rb
index d1f4a12d8fc..c4623061944 100644
--- a/spec/tasks/gitlab/db_rake_spec.rb
+++ b/spec/tasks/gitlab/db_rake_spec.rb
@@ -298,15 +298,15 @@ RSpec.describe 'gitlab:db namespace rake task' do
end
describe '#migrate_with_instrumentation' do
- subject { run_rake_task('gitlab:db:migration_testing', "[#{filename}]") }
+ subject { run_rake_task('gitlab:db:migration_testing') }
let(:ctx) { double('ctx', migrations: all_migrations, schema_migration: double, get_all_versions: existing_versions) }
let(:instrumentation) { instance_double(Gitlab::Database::Migrations::Instrumentation, observations: observations) }
let(:existing_versions) { [1] }
let(:all_migrations) { [double('migration1', version: 1), pending_migration] }
let(:pending_migration) { double('migration2', version: 2) }
- let(:filename) { 'results-file.json'}
- let(:buffer) { StringIO.new }
+ let(:filename) { Gitlab::Database::Migrations::Instrumentation::STATS_FILENAME }
+ let!(:directory) { Dir.mktmpdir }
let(:observations) { %w[some data] }
before do
@@ -316,17 +316,19 @@ RSpec.describe 'gitlab:db namespace rake task' do
allow(instrumentation).to receive(:observe).and_yield
- allow(File).to receive(:open).with(filename, 'wb+').and_yield(buffer)
+ allow(Dir).to receive(:mkdir)
+ allow(File).to receive(:exist?).with(directory).and_return(false)
+ stub_const('Gitlab::Database::Migrations::Instrumentation::RESULT_DIR', directory)
end
- it 'fails when given no filename argument' do
- expect { run_rake_task('gitlab:db:migration_testing') }.to raise_error(/specify result_file/)
+ after do
+ FileUtils.rm_rf([directory])
end
- it 'fails when the given file already exists' do
- expect(File).to receive(:exist?).with(filename).and_return(true)
+ it 'fails when the directory already exists' do
+ expect(File).to receive(:exist?).with(directory).and_return(true)
- expect { subject }.to raise_error(/File exists/)
+ expect { subject }.to raise_error(/Directory exists/)
end
it 'instruments the pending migration' do
@@ -344,7 +346,27 @@ RSpec.describe 'gitlab:db namespace rake task' do
it 'writes observations out to JSON file' do
subject
- expect(buffer.string).to eq(observations.to_json)
+ expect(File.read(File.join(directory, filename))).to eq(observations.to_json)
+ end
+ end
+
+ describe '#execute_batched_migrations' do
+ subject { run_rake_task('gitlab:db:execute_batched_migrations') }
+
+ let(:migrations) { create_list(:batched_background_migration, 2) }
+ let(:runner) { instance_double('Gitlab::Database::BackgroundMigration::BatchedMigrationRunner') }
+
+ before do
+ allow(Gitlab::Database::BackgroundMigration::BatchedMigration).to receive_message_chain(:active, :queue_order).and_return(migrations)
+ allow(Gitlab::Database::BackgroundMigration::BatchedMigrationRunner).to receive(:new).and_return(runner)
+ end
+
+ it 'executes all migrations' do
+ migrations.each do |migration|
+ expect(runner).to receive(:run_entire_migration).with(migration)
+ end
+
+ subject
end
end
diff --git a/spec/tasks/gitlab/sidekiq_rake_spec.rb b/spec/tasks/gitlab/sidekiq_rake_spec.rb
new file mode 100644
index 00000000000..61a8aecfa61
--- /dev/null
+++ b/spec/tasks/gitlab/sidekiq_rake_spec.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+require 'rake_helper'
+
+RSpec.describe 'sidekiq.rake', :aggregate_failures do
+ before do
+ Rake.application.rake_require 'tasks/gitlab/sidekiq'
+
+ stub_warn_user_is_not_gitlab
+ end
+
+ shared_examples 'migration rake task' do
+ it 'runs the migrator with a mapping of workers to queues' do
+ test_routes = [
+ ['urgency=high', 'default'],
+ ['*', nil]
+ ]
+
+ test_router = ::Gitlab::SidekiqConfig::WorkerRouter.new(test_routes)
+ migrator = ::Gitlab::SidekiqMigrateJobs.new(sidekiq_set, logger: Logger.new($stdout))
+
+ allow(::Gitlab::SidekiqConfig::WorkerRouter)
+ .to receive(:global).and_return(test_router)
+
+ expect(::Gitlab::SidekiqMigrateJobs)
+ .to receive(:new).with(sidekiq_set, logger: an_instance_of(Logger)).and_return(migrator)
+
+ expect(migrator)
+ .to receive(:execute)
+ .with(a_hash_including('PostReceive' => 'default',
+ 'MergeWorker' => 'default',
+ 'DeleteDiffFilesWorker' => 'delete_diff_files'))
+ .and_call_original
+
+ run_rake_task("gitlab:sidekiq:migrate_jobs:#{sidekiq_set}")
+
+ expect($stdout.string).to include("Processing #{sidekiq_set}")
+ expect($stdout.string).to include('Done')
+ end
+ end
+
+ describe 'gitlab:sidekiq:migrate_jobs:schedule rake task' do
+ let(:sidekiq_set) { 'schedule' }
+
+ it_behaves_like 'migration rake task'
+ end
+
+ describe 'gitlab:sidekiq:migrate_jobs:retry rake task' do
+ let(:sidekiq_set) { 'retry' }
+
+ it_behaves_like 'migration rake task'
+ end
+end