Skip to content

Fix run_after_commit_or_now to use model's connection

What does this MR do and why?

Fix run_after_commit_or_now to use model's connection

Related issue: #346309 (closed)

Screenshots or screen recordings

Before the application changes:

$ GITLAB_USE_MODEL_LOAD_BALANCING=1 bin/rspec spec/models/concerns/after_commit_queue_spec.rb 
Run options: include {:focus=>true}

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

Test environment set up in 6.592182 seconds
.....F

Failures:

  1) AfterCommitQueue#run_after_commit_or_now multiple databases - Ci::ApplicationRecord models runs after transaction has completed
     Failure/Error: expect(called).to be false
     
       expected false
            got true
     # ./spec/models/concerns/after_commit_queue_spec.rb:121:in `block (5 levels) in <top (required)>'
     # ./lib/gitlab/database/load_balancing/connection_proxy.rb:126:in `block in write_using_load_balancer'
     # ./lib/gitlab/database/load_balancing/load_balancer.rb:112:in `block in read_write'
     # ./lib/gitlab/database/load_balancing/load_balancer.rb:172:in `retry_with_backoff'
     # ./lib/gitlab/database/load_balancing/load_balancer.rb:110:in `read_write'
     # ./lib/gitlab/database/load_balancing/connection_proxy.rb:125:in `write_using_load_balancer'
     # ./lib/gitlab/database/load_balancing/connection_proxy.rb:77:in `transaction'
     # ./lib/gitlab/database.rb:261:in `block in transaction'
     # ./lib/gitlab/database.rb:260:in `transaction'
     # ./spec/models/concerns/after_commit_queue_spec.rb:112:in `block (4 levels) in <top (required)>'
     # ./spec/spec_helper.rb:412:in `block (3 levels) in <top (required)>'
     # ./spec/support/sidekiq_middleware.rb:9:in `with_sidekiq_server_middleware'
     # ./spec/spec_helper.rb:403:in `block (2 levels) in <top (required)>'
     # ./spec/spec_helper.rb:399:in `block (3 levels) in <top (required)>'
     # ./lib/gitlab/application_context.rb:31:in `with_raw_context'
     # ./spec/spec_helper.rb:399:in `block (2 levels) in <top (required)>'
     # ./spec/support/database/query_analyzer.rb:9:in `block (3 levels) in <main>'
     # ./lib/gitlab/database/query_analyzer.rb:42:in `within'
     # ./spec/support/database/query_analyzer.rb:9:in `block (2 levels) in <main>'
     # ./spec/support/database/prevent_cross_joins.rb:106:in `block (3 levels) in <main>'
     # ./spec/support/database/prevent_cross_joins.rb:60:in `with_cross_joins_prevented'
     # ./spec/support/database/prevent_cross_joins.rb:106:in `block (2 levels) in <main>'

Finished in 10.89 seconds (files took 10.47 seconds to load)
6 examples, 1 failure

Failed examples:

rspec ./spec/models/concerns/after_commit_queue_spec.rb:108 # AfterCommitQueue#run_after_commit_or_now multiple databases - Ci::ApplicationRecord models runs after transaction has completed

After:

$ GITLAB_USE_MODEL_LOAD_BALANCING=1 bin/rspec spec/models/concerns/after_commit_queue_spec.rb
Run options: include {:focus=>true}

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

Test environment set up in 6.623249 seconds
......

Finished in 10.78 seconds (files took 10.65 seconds to load)
6 examples, 0 failures

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