Skip to content

Fix fake connection leaking for Ci::ApplicationRecord

Thong Kuah requested to merge fix_connection_leak_load_balancer_spec into master

What does this MR do and why?

Fix fake connection leaking for Ci::ApplicationRecord

After the example has run, the Ci::ApplicationRecord#connection_specification_name remained stuck as "Ci::ApplicationRecord" instead of reverting back to "ActiveRecord::Base".

We call model.remove_connection to fix this.

Also, there is no need to setup a (fake) ci connection, if we already have one

Fixes #345181 (closed)

Screenshots or screen recordings

The minimal set of specs passes under all scenarios:

  1. With ci: configured in config/database.yml
  2. With ci: configured in config/database.yml, with GITLAB_LOAD_BALANCING_REUSE_PRIMARY_ci=main
  3. Without ci: configured in config/database.yml
$ bundle exec rspec spec/lib/gitlab/database/load_balancing/load_balancer_spec.rb spec/models/acts_as_taggable_on/tagging_spec.rb
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}

Test environment set up in 9.662431 seconds
.................................................

Finished in 15.78 seconds (files took 20.04 seconds to load)
49 examples, 0 failures

These are strongly recommended to assist reviewers and reduce the time to merge your change.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

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