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:
Diffstat (limited to 'spec/tasks/gitlab/db_rake_spec.rb')
-rw-r--r--spec/tasks/gitlab/db_rake_spec.rb173
1 files changed, 171 insertions, 2 deletions
diff --git a/spec/tasks/gitlab/db_rake_spec.rb b/spec/tasks/gitlab/db_rake_spec.rb
index 7671c65d22c..933eba40719 100644
--- a/spec/tasks/gitlab/db_rake_spec.rb
+++ b/spec/tasks/gitlab/db_rake_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
require 'rake'
-RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do
+RSpec.describe 'gitlab:db namespace rake task', :silence_stdout, feature_category: :database do
before :all do
Rake.application.rake_require 'active_record/railties/databases'
Rake.application.rake_require 'tasks/seed_fu'
@@ -352,6 +352,101 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do
end
end
+ describe 'dictionary generate' do
+ let(:db_config) { instance_double(ActiveRecord::DatabaseConfigurations::HashConfig, name: 'fake_db') }
+
+ let(:model) { ActiveRecord::Base }
+ let(:connection) { model.connection }
+
+ let(:base_models) { { 'fake_db' => model }.with_indifferent_access }
+
+ let(:tables) { %w[table1 _test_dictionary_table_name] }
+ let(:views) { %w[view1] }
+
+ let(:table_file_path) { 'db/docs/table1.yml' }
+ let(:view_file_path) { 'db/docs/views/view1.yml' }
+ let(:test_table_path) { 'db/docs/_test_dictionary_table_name.yml' }
+
+ before do
+ allow(Gitlab::Database).to receive(:db_config_for_connection).and_return(db_config)
+ allow(Gitlab::Database).to receive(:database_base_models).and_return(base_models)
+
+ allow(connection).to receive(:tables).and_return(tables)
+ allow(connection).to receive(:views).and_return(views)
+ end
+
+ after do
+ File.delete(table_file_path)
+ File.delete(view_file_path)
+ end
+
+ context 'when the dictionary files do not exist' do
+ it 'generate the dictionary files' do
+ run_rake_task('gitlab:db:dictionary:generate')
+
+ expect(File).to exist(File.join(table_file_path))
+ expect(File).to exist(File.join(view_file_path))
+ end
+
+ it 'do not generate the dictionary files for test tables' do
+ run_rake_task('gitlab:db:dictionary:generate')
+
+ expect(File).not_to exist(File.join(test_table_path))
+ end
+ end
+
+ context 'when the dictionary files already exist' do
+ let(:table_class) do
+ Class.new(ApplicationRecord) do
+ self.table_name = 'table1'
+ end
+ end
+
+ let(:view_class) do
+ Class.new(ApplicationRecord) do
+ self.table_name = 'view1'
+ end
+ end
+
+ table_metadata = {
+ 'table_name' => 'table1',
+ 'classes' => [],
+ 'feature_categories' => [],
+ 'description' => nil,
+ 'introduced_by_url' => nil,
+ 'milestone' => 14.3
+ }
+ view_metadata = {
+ 'view_name' => 'view1',
+ 'classes' => [],
+ 'feature_categories' => [],
+ 'description' => nil,
+ 'introduced_by_url' => nil,
+ 'milestone' => 14.3
+ }
+
+ before do
+ stub_const('TableClass', table_class)
+ stub_const('ViewClass', view_class)
+
+ File.write(table_file_path, table_metadata.to_yaml)
+ File.write(view_file_path, view_metadata.to_yaml)
+
+ allow(model).to receive(:descendants).and_return([table_class, view_class])
+ end
+
+ it 'update the dictionary content' do
+ run_rake_task('gitlab:db:dictionary:generate')
+
+ table_metadata = YAML.safe_load(File.read(table_file_path))
+ expect(table_metadata['classes']).to match_array(['TableClass'])
+
+ view_metadata = YAML.safe_load(File.read(view_file_path))
+ expect(view_metadata['classes']).to match_array(['ViewClass'])
+ end
+ end
+ end
+
describe 'unattended' do
using RSpec::Parameterized::TableSyntax
@@ -573,7 +668,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do
let(:base_models) { { 'main' => double(:model), 'ci' => double(:model) } }
before do
- skip_if_multiple_databases_not_setup
+ skip_if_multiple_databases_not_setup(:ci)
allow(Gitlab::Database).to receive(:database_base_models_with_gitlab_shared).and_return(base_models)
end
@@ -636,6 +731,80 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do
end
end
+ describe 'execute_async_index_operations' do
+ before do
+ skip_if_multiple_databases_not_setup
+ end
+
+ it 'delegates ci task to Gitlab::Database::AsyncIndexes' do
+ expect(Gitlab::Database::AsyncIndexes).to receive(:execute_pending_actions!).with(how_many: 2)
+
+ run_rake_task('gitlab:db:execute_async_index_operations:ci')
+ end
+
+ it 'delegates ci task to Gitlab::Database::AsyncIndexes with specified argument' do
+ expect(Gitlab::Database::AsyncIndexes).to receive(:execute_pending_actions!).with(how_many: 5)
+
+ run_rake_task('gitlab:db:execute_async_index_operations:ci', '[5]')
+ end
+
+ it 'delegates main task to Gitlab::Database::AsyncIndexes' do
+ expect(Gitlab::Database::AsyncIndexes).to receive(:execute_pending_actions!).with(how_many: 2)
+
+ run_rake_task('gitlab:db:execute_async_index_operations:main')
+ end
+
+ it 'delegates main task to Gitlab::Database::AsyncIndexes with specified argument' do
+ expect(Gitlab::Database::AsyncIndexes).to receive(:execute_pending_actions!).with(how_many: 7)
+
+ run_rake_task('gitlab:db:execute_async_index_operations:main', '[7]')
+ end
+
+ it 'delegates all task to every database with higher default for dev' do
+ expect(Rake::Task['gitlab:db:execute_async_index_operations:ci']).to receive(:invoke).with(1000)
+ expect(Rake::Task['gitlab:db:execute_async_index_operations:main']).to receive(:invoke).with(1000)
+
+ run_rake_task('gitlab:db:execute_async_index_operations:all')
+ end
+
+ it 'delegates all task to every database with lower default for prod' do
+ allow(Gitlab).to receive(:dev_or_test_env?).and_return(false)
+
+ expect(Rake::Task['gitlab:db:execute_async_index_operations:ci']).to receive(:invoke).with(2)
+ expect(Rake::Task['gitlab:db:execute_async_index_operations:main']).to receive(:invoke).with(2)
+
+ run_rake_task('gitlab:db:execute_async_index_operations:all')
+ end
+
+ it 'delegates all task to every database with specified argument' do
+ expect(Rake::Task['gitlab:db:execute_async_index_operations:ci']).to receive(:invoke).with('50')
+ expect(Rake::Task['gitlab:db:execute_async_index_operations:main']).to receive(:invoke).with('50')
+
+ run_rake_task('gitlab:db:execute_async_index_operations:all', '[50]')
+ end
+
+ context 'when feature is not enabled' do
+ it 'is a no-op' do
+ stub_feature_flags(database_async_index_operations: false)
+
+ expect(Gitlab::Database::AsyncIndexes).not_to receive(:execute_pending_actions!)
+
+ expect { run_rake_task('gitlab:db:execute_async_index_operations:main') }.to raise_error(SystemExit)
+ end
+ end
+
+ context 'with geo configured' do
+ before do
+ skip_unless_geo_configured
+ end
+
+ it 'does not create a task for the geo database' do
+ expect { run_rake_task('gitlab:db:execute_async_index_operations:geo') }
+ .to raise_error(/Don't know how to build task 'gitlab:db:execute_async_index_operations:geo'/)
+ end
+ end
+ end
+
describe 'active' do
using RSpec::Parameterized::TableSyntax