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')
-rw-r--r--spec/tasks/gitlab/background_migrations_rake_spec.rb4
-rw-r--r--spec/tasks/gitlab/backup_rake_spec.rb13
-rw-r--r--spec/tasks/gitlab/db/decomposition/rollback/bump_ci_sequences_rake_spec.rb3
-rw-r--r--spec/tasks/gitlab/db/lock_writes_rake_spec.rb80
-rw-r--r--spec/tasks/gitlab/db/validate_config_rake_spec.rb2
-rw-r--r--spec/tasks/gitlab/db_rake_spec.rb2
-rw-r--r--spec/tasks/gitlab/gitaly_rake_spec.rb8
-rw-r--r--spec/tasks/gitlab/password_rake_spec.rb9
-rw-r--r--spec/tasks/gitlab/web_hook_rake_spec.rb4
9 files changed, 44 insertions, 81 deletions
diff --git a/spec/tasks/gitlab/background_migrations_rake_spec.rb b/spec/tasks/gitlab/background_migrations_rake_spec.rb
index bbd33f71e60..d8ce00a65e6 100644
--- a/spec/tasks/gitlab/background_migrations_rake_spec.rb
+++ b/spec/tasks/gitlab/background_migrations_rake_spec.rb
@@ -2,7 +2,7 @@
require 'rake_helper'
-RSpec.describe 'gitlab:background_migrations namespace rake tasks' do
+RSpec.describe 'gitlab:background_migrations namespace rake tasks', :suppress_gitlab_schemas_validate_connection do
before do
Rake.application.rake_require 'tasks/gitlab/background_migrations'
end
@@ -155,7 +155,7 @@ RSpec.describe 'gitlab:background_migrations namespace rake tasks' do
context 'with multiple databases' do
subject(:status_task) { run_rake_task('gitlab:background_migrations:status') }
- let(:base_models) { { 'main' => main_model, 'ci' => ci_model } }
+ let(:base_models) { { main: main_model, ci: ci_model } }
let(:main_model) { double(:model, connection: connection) }
let(:ci_model) { double(:model, connection: connection) }
diff --git a/spec/tasks/gitlab/backup_rake_spec.rb b/spec/tasks/gitlab/backup_rake_spec.rb
index 9e914f8202e..dc112b885ae 100644
--- a/spec/tasks/gitlab/backup_rake_spec.rb
+++ b/spec/tasks/gitlab/backup_rake_spec.rb
@@ -5,7 +5,11 @@ require 'rake_helper'
RSpec.describe 'gitlab:app namespace rake task', :delete do
let(:enable_registry) { true }
let(:backup_tasks) { %w{db repo uploads builds artifacts pages lfs terraform_state registry packages} }
- let(:backup_types) { %w{db repositories uploads builds artifacts pages lfs terraform_state registry packages} }
+ let(:backup_types) do
+ %w{main_db repositories uploads builds artifacts pages lfs terraform_state registry packages}.tap do |array|
+ array.insert(1, 'ci_db') if Gitlab::Database.has_config?(:ci)
+ end
+ end
def tars_glob
Dir.glob(File.join(Gitlab.config.backup.path, '*_gitlab_backup.tar'))
@@ -151,7 +155,8 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do
describe 'backup' do
before do
# This reconnect makes our project fixture disappear, breaking the restore. Stub it out.
- allow(ActiveRecord::Base.connection).to receive(:reconnect!)
+ allow(ApplicationRecord.connection).to receive(:reconnect!)
+ allow(Ci::ApplicationRecord.connection).to receive(:reconnect!)
end
let!(:project) { create(:project, :repository) }
@@ -199,7 +204,9 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do
end
it 'logs the progress to log file' do
- expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping database ... [SKIPPED]")
+ ci_database_status = Gitlab::Database.has_config?(:ci) ? "[SKIPPED]" : "[DISABLED]"
+ expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping main_database ... [SKIPPED]")
+ expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping ci_database ... #{ci_database_status}")
expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping repositories ... ")
expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping repositories ... done")
expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping uploads ... ")
diff --git a/spec/tasks/gitlab/db/decomposition/rollback/bump_ci_sequences_rake_spec.rb b/spec/tasks/gitlab/db/decomposition/rollback/bump_ci_sequences_rake_spec.rb
index 29b80176ef8..b03e964ce87 100644
--- a/spec/tasks/gitlab/db/decomposition/rollback/bump_ci_sequences_rake_spec.rb
+++ b/spec/tasks/gitlab/db/decomposition/rollback/bump_ci_sequences_rake_spec.rb
@@ -2,7 +2,8 @@
require 'rake_helper'
-RSpec.describe 'gitlab:db:decomposition:rollback:bump_ci_sequences', :silence_stdout do
+RSpec.describe 'gitlab:db:decomposition:rollback:bump_ci_sequences', :silence_stdout,
+ :suppress_gitlab_schemas_validate_connection do
before :all do
Rake.application.rake_require 'tasks/gitlab/db/decomposition/rollback/bump_ci_sequences'
diff --git a/spec/tasks/gitlab/db/lock_writes_rake_spec.rb b/spec/tasks/gitlab/db/lock_writes_rake_spec.rb
index 034c520887e..d03e15224cb 100644
--- a/spec/tasks/gitlab/db/lock_writes_rake_spec.rb
+++ b/spec/tasks/gitlab/db/lock_writes_rake_spec.rb
@@ -2,7 +2,8 @@
require 'rake_helper'
-RSpec.describe 'gitlab:db:lock_writes', :silence_stdout, :reestablished_active_record_base do
+RSpec.describe 'gitlab:db:lock_writes', :silence_stdout, :reestablished_active_record_base,
+ :suppress_gitlab_schemas_validate_connection do
before :all do
Rake.application.rake_require 'active_record/railties/databases'
Rake.application.rake_require 'tasks/seed_fu'
@@ -48,26 +49,6 @@ RSpec.describe 'gitlab:db:lock_writes', :silence_stdout, :reestablished_active_r
end
context 'when locking writes' do
- it 'adds 3 triggers to the ci schema tables on the main database' do
- expect do
- run_rake_task('gitlab:db:lock_writes')
- end.to change {
- number_of_triggers_on(main_connection, Ci::Build.table_name)
- }.by(3) # Triggers to block INSERT / UPDATE / DELETE
- # Triggers on TRUNCATE are not added to the information_schema.triggers
- # See https://www.postgresql.org/message-id/16934.1568989957%40sss.pgh.pa.us
- end
-
- it 'adds 3 triggers to the main schema tables on the ci database' do
- expect do
- run_rake_task('gitlab:db:lock_writes')
- end.to change {
- number_of_triggers_on(ci_connection, Project.table_name)
- }.by(3) # Triggers to block INSERT / UPDATE / DELETE
- # Triggers on TRUNCATE are not added to the information_schema.triggers
- # See https://www.postgresql.org/message-id/16934.1568989957%40sss.pgh.pa.us
- end
-
it 'still allows writes on the tables with the correct connections' do
Project.update_all(updated_at: Time.now)
Ci::Build.update_all(updated_at: Time.now)
@@ -106,30 +87,22 @@ RSpec.describe 'gitlab:db:lock_writes', :silence_stdout, :reestablished_active_r
main_connection.execute("truncate ci_build_needs")
end.to raise_error(ActiveRecord::StatementInvalid, /Table: "ci_build_needs" is write protected/)
end
+ end
- it 'retries again if it receives a statement_timeout a few number of times' do
- error_message = "PG::QueryCanceled: ERROR: canceling statement due to statement timeout"
- call_count = 0
- allow(main_connection).to receive(:execute) do |statement|
- if statement.include?("CREATE TRIGGER")
- call_count += 1
- raise(ActiveRecord::QueryCanceled, error_message) if call_count.even?
- end
- end
- run_rake_task('gitlab:db:lock_writes')
+ context 'multiple shared databases' do
+ before do
+ allow(::Gitlab::Database).to receive(:db_config_share_with).and_return(nil)
+ ci_db_config = Ci::ApplicationRecord.connection_db_config
+ allow(::Gitlab::Database).to receive(:db_config_share_with).with(ci_db_config).and_return('main')
end
- it 'raises the exception if it happened many times' do
- error_message = "PG::QueryCanceled: ERROR: canceling statement due to statement timeout"
- allow(main_connection).to receive(:execute) do |statement|
- if statement.include?("CREATE TRIGGER")
- raise(ActiveRecord::QueryCanceled, error_message)
- end
- end
+ it 'does not lock any tables if the ci database is shared with main database' do
+ run_rake_task('gitlab:db:lock_writes')
expect do
- run_rake_task('gitlab:db:lock_writes')
- end.to raise_error(ActiveRecord::QueryCanceled)
+ ApplicationRecord.connection.execute("delete from ci_builds")
+ Ci::ApplicationRecord.connection.execute("delete from users")
+ end.not_to raise_error
end
end
@@ -138,26 +111,8 @@ RSpec.describe 'gitlab:db:lock_writes', :silence_stdout, :reestablished_active_r
run_rake_task('gitlab:db:lock_writes')
end
- it 'removes the write protection triggers from the gitlab_main tables on the ci database' do
- expect do
- run_rake_task('gitlab:db:unlock_writes')
- end.to change {
- number_of_triggers_on(ci_connection, Project.table_name)
- }.by(-3) # Triggers to block INSERT / UPDATE / DELETE
- # Triggers on TRUNCATE are not added to the information_schema.triggers
- # See https://www.postgresql.org/message-id/16934.1568989957%40sss.pgh.pa.us
-
- expect do
- ci_connection.execute("delete from projects")
- end.not_to raise_error
- end
-
- it 'removes the write protection triggers from the gitlab_ci tables on the main database' do
- expect do
- run_rake_task('gitlab:db:unlock_writes')
- end.to change {
- number_of_triggers_on(main_connection, Ci::Build.table_name)
- }.by(-3)
+ it 'allows writes again on the gitlab_ci tables on the main database' do
+ run_rake_task('gitlab:db:unlock_writes')
expect do
main_connection.execute("delete from ci_builds")
@@ -169,9 +124,4 @@ RSpec.describe 'gitlab:db:lock_writes', :silence_stdout, :reestablished_active_r
def number_of_triggers(connection)
connection.select_value("SELECT count(*) FROM information_schema.triggers")
end
-
- def number_of_triggers_on(connection, table_name)
- connection
- .select_value("SELECT count(*) FROM information_schema.triggers WHERE event_object_table=$1", nil, [table_name])
- end
end
diff --git a/spec/tasks/gitlab/db/validate_config_rake_spec.rb b/spec/tasks/gitlab/db/validate_config_rake_spec.rb
index 03d7504e8b1..ad15c7f0d1c 100644
--- a/spec/tasks/gitlab/db/validate_config_rake_spec.rb
+++ b/spec/tasks/gitlab/db/validate_config_rake_spec.rb
@@ -2,7 +2,7 @@
require 'rake_helper'
-RSpec.describe 'gitlab:db:validate_config', :silence_stdout do
+RSpec.describe 'gitlab:db:validate_config', :silence_stdout, :suppress_gitlab_schemas_validate_connection do
# We don't need to delete this data since it only modifies `ar_internal_metadata`
# which would not be cleaned either by `DbCleaner`
self.use_transactional_tests = false
diff --git a/spec/tasks/gitlab/db_rake_spec.rb b/spec/tasks/gitlab/db_rake_spec.rb
index 74bec406947..8f8178cde4d 100644
--- a/spec/tasks/gitlab/db_rake_spec.rb
+++ b/spec/tasks/gitlab/db_rake_spec.rb
@@ -370,7 +370,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do
it 'outputs changed message for automation after operations happen' do
allow(ActiveRecord::Base.connection.schema_migration).to receive(:table_exists?).and_return(schema_migration_table_exists)
allow_any_instance_of(ActiveRecord::MigrationContext).to receive(:needs_migration?).and_return(needs_migrations)
- expect { run_rake_task('gitlab:db:unattended') }. to output(/^#{rake_output}$/).to_stdout
+ expect { run_rake_task('gitlab:db:unattended') }.to output(/^#{rake_output}$/).to_stdout
end
end
end
diff --git a/spec/tasks/gitlab/gitaly_rake_spec.rb b/spec/tasks/gitlab/gitaly_rake_spec.rb
index 70c7ddb1d6e..e57021f749b 100644
--- a/spec/tasks/gitlab/gitaly_rake_spec.rb
+++ b/spec/tasks/gitlab/gitaly_rake_spec.rb
@@ -66,7 +66,7 @@ RSpec.describe 'gitlab:gitaly namespace rake task', :silence_stdout do
.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 })
+ .with(%w[gmake clean-build all git], nil, { "BUNDLE_GEMFILE" => nil, "RUBYOPT" => nil })
.and_return(['ok', 0])
subject
@@ -78,7 +78,7 @@ RSpec.describe 'gitlab:gitaly namespace rake task', :silence_stdout do
.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 })
+ .with(%w[gmake clean-build all git], nil, { "BUNDLE_GEMFILE" => nil, "RUBYOPT" => nil })
.and_return(['output', 1])
expect { subject }.to raise_error /Gitaly failed to compile: output/
@@ -95,14 +95,14 @@ RSpec.describe 'gitlab:gitaly namespace rake task', :silence_stdout do
it 'calls make in the gitaly directory' do
expect(Gitlab::Popen).to receive(:popen)
- .with(%w[make all git], nil, { "BUNDLE_GEMFILE" => nil, "RUBYOPT" => nil })
+ .with(%w[make clean-build 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 all git] }
+ let(:command) { %w[make clean-build all git] }
before do
stub_rails_env('test')
diff --git a/spec/tasks/gitlab/password_rake_spec.rb b/spec/tasks/gitlab/password_rake_spec.rb
index 65bba836024..5d5e5af2536 100644
--- a/spec/tasks/gitlab/password_rake_spec.rb
+++ b/spec/tasks/gitlab/password_rake_spec.rb
@@ -3,7 +3,8 @@
require 'rake_helper'
RSpec.describe 'gitlab:password rake tasks', :silence_stdout do
- let_it_be(:user_1) { create(:user, username: 'foobar', password: 'initial_password') }
+ let_it_be(:user_1) { create(:user, username: 'foobar', password: User.random_password) }
+ let_it_be(:password) { User.random_password }
def stub_username(username)
allow(Gitlab::TaskHelpers).to receive(:prompt).with('Enter username: ').and_return(username)
@@ -19,14 +20,14 @@ RSpec.describe 'gitlab:password rake tasks', :silence_stdout do
Rake.application.rake_require 'tasks/gitlab/password'
stub_username('foobar')
- stub_password('secretpassword')
+ stub_password(password)
end
describe ':reset' do
context 'when all inputs are correct' do
it 'updates the password properly' do
run_rake_task('gitlab:password:reset', user_1.username)
- expect(user_1.reload.valid_password?('secretpassword')).to eq(true)
+ expect(user_1.reload.valid_password?(password)).to eq(true)
end
end
@@ -55,7 +56,7 @@ RSpec.describe 'gitlab:password rake tasks', :silence_stdout do
context 'when passwords do not match' do
before do
- stub_password('randompassword', 'differentpassword')
+ stub_password(password, User.random_password)
end
it 'aborts with an error' do
diff --git a/spec/tasks/gitlab/web_hook_rake_spec.rb b/spec/tasks/gitlab/web_hook_rake_spec.rb
index 2c582dc78f8..cb6a6e72ab1 100644
--- a/spec/tasks/gitlab/web_hook_rake_spec.rb
+++ b/spec/tasks/gitlab/web_hook_rake_spec.rb
@@ -50,6 +50,10 @@ RSpec.describe 'gitlab:web_hook namespace rake tasks', :silence_stdout do
let(:other_url) { 'http://other.example.com' }
+ it 'complains if URL is not provided' do
+ expect { run_rake_task('gitlab:web_hook:rm') }.to raise_error(ArgumentError, 'URL is required')
+ end
+
it 'removes a web hook from all projects by URL' do
stub_env('URL' => url)
run_rake_task('gitlab:web_hook:rm')