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>2022-05-19 10:33:21 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-05-19 10:33:21 +0300
commit36a59d088eca61b834191dacea009677a96c052f (patch)
treee4f33972dab5d8ef79e3944a9f403035fceea43f /spec/support/shared_examples/lib/gitlab/database/reestablished_connection_stack_shared_examples.rb
parenta1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff)
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/support/shared_examples/lib/gitlab/database/reestablished_connection_stack_shared_examples.rb')
-rw-r--r--spec/support/shared_examples/lib/gitlab/database/reestablished_connection_stack_shared_examples.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/spec/support/shared_examples/lib/gitlab/database/reestablished_connection_stack_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/database/reestablished_connection_stack_shared_examples.rb
new file mode 100644
index 00000000000..67d739b79ab
--- /dev/null
+++ b/spec/support/shared_examples/lib/gitlab/database/reestablished_connection_stack_shared_examples.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+RSpec.shared_context 'reconfigures connection stack' do |db_config_name|
+ before do
+ skip_if_multiple_databases_not_setup
+
+ # Due to lib/gitlab/database/load_balancing/configuration.rb:92 requiring RequestStore
+ # we cannot use stub_feature_flags(force_no_sharing_primary_model: true)
+ Gitlab::Database.database_base_models.each do |_, model_class|
+ allow(model_class.load_balancer.configuration).to receive(:use_dedicated_connection?).and_return(true)
+ end
+
+ ActiveRecord::Base.establish_connection(db_config_name.to_sym) # rubocop:disable Database/EstablishConnection
+
+ expect(Gitlab::Database.db_config_name(ActiveRecord::Base.connection)) # rubocop:disable Database/MultipleDatabases
+ .to eq(db_config_name)
+ end
+
+ around do |example|
+ with_reestablished_active_record_base do
+ example.run
+ end
+ end
+
+ def validate_connections!
+ model_connections = Gitlab::Database.database_base_models.to_h do |db_config_name, model_class|
+ [model_class, Gitlab::Database.db_config_name(model_class.connection)]
+ end
+
+ expect(model_connections).to eq(Gitlab::Database.database_base_models.invert)
+ end
+end