Add test for load_balancing initializer
What does this MR do and why?
Add test for load_balancing initializer. While not a perfect test (because 3 things are stubbed out), it functions as an early warning system.
I considered a feature test but it turns out that Capybara is incompatible with puma where
workers > 0
so this is the best option. As a follow-up, a new QA scenario should be created
to test that GitLab setup with DB load balancing works with our E2E tests.
Related issue: #333184 (closed)
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
How to set up and validate locally
How to reproduce the original problem
- Setup DB load balancing in development. The simplest way will be to add
load_balancing:
poiting to the samehost:
. Here's how myconfig/database.yml
looks like:
development:
main:
adapter: postgresql
encoding: unicode
database: gitlabhq_development
host: /Users/tkuah/code/gdk-ee/postgresql
port: 5432
pool: 10
prepared_statements: false
variables:
statement_timeout: 120s
load_balancing:
hosts:
- /Users/tkuah/code/gdk-ee/postgresql
- /Users/tkuah/code/gdk-ee/postgresql
ci:
adapter: postgresql
encoding: unicode
database: gitlabhq_development_ci
host: /Users/tkuah/code/gdk-ee/postgresql
port: 5432
pool: 10
prepared_statements: false
variables:
statement_timeout: 120s
load_balancing:
hosts:
- /Users/tkuah/code/gdk-ee/postgresql
- /Users/tkuah/code/gdk-ee/postgresql
- In
config/initializers/load_balancing.rb
, comment out the inside of theon_worker_start
block gdk restart
- Navigate to any page. You should observe an error similar to #332913 (closed)
Running this new test:
- Restore any changes to
config/initializers/load_balancing.rb
-
bundle exec rspec spec/initializers/load_balancing_spec.rb
. This test should pass. Note this test sets up DB load balancing for itself. - In
config/initializers/load_balancing.rb
, comment out the inside of theon_worker_start
block - Run
bundle exec rspec spec/initializers/load_balancing_spec.rb
, observe the error / failure
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Thong Kuah