Commit aa4fe6ab authored by Thong Kuah's avatar Thong Kuah

Do not set the env var globally, but use ENV.fetch

parent 1d5c9729
......@@ -6,11 +6,6 @@ require 'gitlab/testing/request_inspector_middleware'
require 'gitlab/testing/clear_process_memory_cache_middleware'
require 'gitlab/utils'
# Set GITLAB_USE_MODEL_LOAD_BALANCING to a non-nil value
# CI tables consistently use the same connection
# See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/82562
ENV['GITLAB_USE_MODEL_LOAD_BALANCING'] ||= 'true'
Rails.application.configure do
# Make sure the middleware is inserted first in middleware chain
config.middleware.insert_before(ActionDispatch::Static, Gitlab::Testing::RequestBlockerMiddleware)
......
......@@ -90,7 +90,8 @@ module Gitlab
def use_model_load_balancing?
# Cache environment variable and return env variable first if defined
use_model_load_balancing_env = Gitlab::Utils.to_boolean(ENV["GITLAB_USE_MODEL_LOAD_BALANCING"])
default_use_model_load_balancing_env = Gitlab.dev_or_test_env? || nil
use_model_load_balancing_env = Gitlab::Utils.to_boolean(ENV.fetch('GITLAB_USE_MODEL_LOAD_BALANCING', default_use_model_load_balancing_env))
unless use_model_load_balancing_env.nil?
return use_model_load_balancing_env
......
......@@ -274,6 +274,8 @@ RSpec.describe Gitlab::Database::LoadBalancing::Setup do
end
before do
allow(Gitlab).to receive(:dev_or_test_env?).and_return(false)
# Rewrite `class_attribute` to use rspec mocking and prevent modifying the objects
allow_next_instance_of(described_class) do |setup|
allow(setup).to receive(:configure_connection)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment