Skip to content

Fix test ordering problem in transaction_leaking_spec and single-db test failure

What does this MR do and why?

I tried a bunch of different ways to fix the test ordering problem described in #382439 (closed) . It seemed that it was not enough to reset the for_model method in after do which makes sense because these stubs are already reset between tests. I needed to also call Setup again on the model because the incorrect host configuration was memoized on the model which is not reset between tests. Then I found this alone was not sufficient beause I noticed that the test is using for_model(ApplicationRecord) which is not actually ever being called in the initializer in normal code execution. It seems it's meant to be ActiveRecord::Base and we do not correctly clear whatever is cached between tests unless we use that consistently.

This problem and solution can be reproduced by running the specs like:

bin/rspec --format documentation --order defined spec/lib/gitlab/database/load_balancing/transaction_leaking_spec.rb spec/initializers/load_balancing_spec.rb

The other commit in this MR is from !103839 (closed) which fixes a test that is not meant to run in single-db and skips for the single-db jobs.

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

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.

Related to #382439 (closed)

Edited by Dylan Griffith

Merge request reports

Loading