summaryrefslogtreecommitdiff
path: root/spec/tasks
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-11-18 13:16:36 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-11-18 13:16:36 +0000
commit311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch)
tree07e7870bca8aed6d61fdcc810731c50d2c40af47 /spec/tasks
parent27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff)
downloadgitlab-ce-311b0269b4eb9839fa63f80c8d7a58f32b8138a0.tar.gz
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'spec/tasks')
-rw-r--r--spec/tasks/gitlab/db_rake_spec.rb46
-rw-r--r--spec/tasks/gitlab/gitaly_rake_spec.rb35
-rw-r--r--spec/tasks/gitlab/storage_rake_spec.rb4
3 files changed, 51 insertions, 34 deletions
diff --git a/spec/tasks/gitlab/db_rake_spec.rb b/spec/tasks/gitlab/db_rake_spec.rb
index ad4ada9a9f1..38392f77307 100644
--- a/spec/tasks/gitlab/db_rake_spec.rb
+++ b/spec/tasks/gitlab/db_rake_spec.rb
@@ -201,9 +201,11 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do
describe 'reindex' do
let(:reindex) { double('reindex') }
let(:indexes) { double('indexes') }
+ let(:databases) { Gitlab::Database.database_base_models }
+ let(:databases_count) { databases.count }
it 'cleans up any leftover indexes' do
- expect(Gitlab::Database::Reindexing).to receive(:cleanup_leftovers!)
+ expect(Gitlab::Database::Reindexing).to receive(:cleanup_leftovers!).exactly(databases_count).times
run_rake_task('gitlab:db:reindex')
end
@@ -212,8 +214,8 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do
it 'executes async index creation prior to any reindexing actions' do
stub_feature_flags(database_async_index_creation: true)
- expect(Gitlab::Database::AsyncIndexes).to receive(:create_pending_indexes!).ordered
- expect(Gitlab::Database::Reindexing).to receive(:perform).ordered
+ expect(Gitlab::Database::AsyncIndexes).to receive(:create_pending_indexes!).ordered.exactly(databases_count).times
+ expect(Gitlab::Database::Reindexing).to receive(:automatic_reindexing).ordered.exactly(databases_count).times
run_rake_task('gitlab:db:reindex')
end
@@ -229,38 +231,30 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do
end
end
- context 'when no index_name is given' do
+ context 'calls automatic reindexing' do
it 'uses all candidate indexes' do
- expect(Gitlab::Database::PostgresIndex).to receive(:reindexing_support).and_return(indexes)
- expect(Gitlab::Database::Reindexing).to receive(:perform).with(indexes)
+ expect(Gitlab::Database::Reindexing).to receive(:automatic_reindexing).exactly(databases_count).times
run_rake_task('gitlab:db:reindex')
end
end
+ end
- context 'with index name given' do
- let(:index) { double('index') }
-
- before do
- allow(Gitlab::Database::PostgresIndex).to receive(:reindexing_support).and_return(indexes)
- end
-
- it 'calls the index rebuilder with the proper arguments' do
- allow(indexes).to receive(:where).with(identifier: 'public.foo_idx').and_return([index])
- expect(Gitlab::Database::Reindexing).to receive(:perform).with([index])
-
- run_rake_task('gitlab:db:reindex', '[public.foo_idx]')
- end
+ describe 'enqueue_reindexing_action' do
+ let(:index_name) { 'public.users_pkey' }
- it 'raises an error if the index does not exist' do
- allow(indexes).to receive(:where).with(identifier: 'public.absent_index').and_return([])
+ it 'creates an entry in the queue' do
+ expect do
+ run_rake_task('gitlab:db:enqueue_reindexing_action', "[#{index_name}, main]")
+ end.to change { Gitlab::Database::PostgresIndex.find(index_name).queued_reindexing_actions.size }.from(0).to(1)
+ end
- expect { run_rake_task('gitlab:db:reindex', '[public.absent_index]') }.to raise_error(/Index not found/)
- end
+ it 'defaults to main database' do
+ expect(Gitlab::Database::SharedModel).to receive(:using_connection).with(ActiveRecord::Base.connection).and_call_original
- it 'raises an error if the index is not fully qualified with a schema' do
- expect { run_rake_task('gitlab:db:reindex', '[foo_idx]') }.to raise_error(/Index name is not fully qualified/)
- end
+ expect do
+ run_rake_task('gitlab:db:enqueue_reindexing_action', "[#{index_name}]")
+ end.to change { Gitlab::Database::PostgresIndex.find(index_name).queued_reindexing_actions.size }.from(0).to(1)
end
end
diff --git a/spec/tasks/gitlab/gitaly_rake_spec.rb b/spec/tasks/gitlab/gitaly_rake_spec.rb
index 5adea832995..c5625db922d 100644
--- a/spec/tasks/gitlab/gitaly_rake_spec.rb
+++ b/spec/tasks/gitlab/gitaly_rake_spec.rb
@@ -67,34 +67,57 @@ RSpec.describe 'gitlab:gitaly namespace rake task', :silence_stdout do
end
it 'calls gmake in the gitaly directory' do
- expect(Gitlab::Popen).to receive(:popen).with(%w[which gmake]).and_return(['/usr/bin/gmake', 0])
- expect(Gitlab::Popen).to receive(:popen).with(%w[gmake], nil, { "BUNDLE_GEMFILE" => nil, "RUBYOPT" => nil }).and_return(true)
+ expect(Gitlab::Popen).to receive(:popen)
+ .with(%w[which gmake])
+ .and_return(['/usr/bin/gmake', 0])
+ expect(Gitlab::Popen).to receive(:popen)
+ .with(%w[gmake all git], nil, { "BUNDLE_GEMFILE" => nil, "RUBYOPT" => nil })
+ .and_return(['ok', 0])
subject
end
+
+ context 'when gmake fails' do
+ it 'aborts process' do
+ expect(Gitlab::Popen).to receive(:popen)
+ .with(%w[which gmake])
+ .and_return(['/usr/bin/gmake', 0])
+ expect(Gitlab::Popen).to receive(:popen)
+ .with(%w[gmake all git], nil, { "BUNDLE_GEMFILE" => nil, "RUBYOPT" => nil })
+ .and_return(['output', 1])
+
+ expect { subject }.to raise_error /Gitaly failed to compile: output/
+ end
+ end
end
context 'gmake is not available' do
before do
expect(main_object).to receive(:checkout_or_clone_version)
- expect(Gitlab::Popen).to receive(:popen).with(%w[which gmake]).and_return(['', 42])
+ expect(Gitlab::Popen).to receive(:popen)
+ .with(%w[which gmake])
+ .and_return(['', 42])
end
it 'calls make in the gitaly directory' do
- expect(Gitlab::Popen).to receive(:popen).with(%w[make], nil, { "BUNDLE_GEMFILE" => nil, "RUBYOPT" => nil }).and_return(true)
+ expect(Gitlab::Popen).to receive(:popen)
+ .with(%w[make all git], nil, { "BUNDLE_GEMFILE" => nil, "RUBYOPT" => nil })
+ .and_return(['output', 0])
subject
end
context 'when Rails.env is test' do
- let(:command) { %w[make] }
+ let(:command) { %w[make all git] }
before do
stub_rails_env('test')
end
it 'calls make in the gitaly directory with BUNDLE_DEPLOYMENT and GEM_HOME variables' do
- expect(Gitlab::Popen).to receive(:popen).with(command, nil, { "BUNDLE_GEMFILE" => nil, "RUBYOPT" => nil, "BUNDLE_DEPLOYMENT" => 'false', "GEM_HOME" => Bundler.bundle_path.to_s }).and_return(true)
+ expect(Gitlab::Popen).to receive(:popen)
+ .with(command, nil, { "BUNDLE_GEMFILE" => nil, "RUBYOPT" => nil, "BUNDLE_DEPLOYMENT" => 'false', "GEM_HOME" => Bundler.bundle_path.to_s })
+ .and_return(['/usr/bin/gmake', 0])
subject
end
diff --git a/spec/tasks/gitlab/storage_rake_spec.rb b/spec/tasks/gitlab/storage_rake_spec.rb
index 570f67c8bb7..38a031178ae 100644
--- a/spec/tasks/gitlab/storage_rake_spec.rb
+++ b/spec/tasks/gitlab/storage_rake_spec.rb
@@ -90,7 +90,7 @@ RSpec.describe 'rake gitlab:storage:*', :silence_stdout do
shared_examples 'wait until database is ready' do
it 'checks if the database is ready once' do
- expect(Gitlab::Database.main).to receive(:exists?).once
+ expect(ApplicationRecord.database).to receive(:exists?).once
run_rake_task(task)
end
@@ -102,7 +102,7 @@ RSpec.describe 'rake gitlab:storage:*', :silence_stdout do
end
it 'tries for 3 times, polling every 0.1 seconds' do
- expect(Gitlab::Database.main).to receive(:exists?).exactly(3).times.and_return(false)
+ expect(ApplicationRecord.database).to receive(:exists?).exactly(3).times.and_return(false)
run_rake_task(task)
end