Skip to content

Add test for load_balancing initializer

Thong Kuah requested to merge db_load_balancing_initializer_tests into master

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

  1. Setup DB load balancing in development. The simplest way will be to add load_balancing: poiting to the same host:. Here's how my config/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
  1. In config/initializers/load_balancing.rb, comment out the inside of the on_worker_start block
  2. gdk restart
  3. Navigate to any page. You should observe an error similar to #332913 (closed)

Running this new test:

  1. Restore any changes to config/initializers/load_balancing.rb
  2. bundle exec rspec spec/initializers/load_balancing_spec.rb. This test should pass. Note this test sets up DB load balancing for itself.
  3. In config/initializers/load_balancing.rb, comment out the inside of the on_worker_start block
  4. 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.

Edited by Thong Kuah

Merge request reports

Loading