Module: E2E::Rails::ActiveRecordSharedConnection
- Defined in:
- lib/e2e/rails.rb
Overview
Shares one ActiveRecord connection between the example thread and the in-process server thread so transactional fixtures remain visible.
Rails 7.2+/8 prefer lease_connection / with_connection over
connection. Overriding only connection (pre-0.7.1) left those
APIs on the pool's thread-local lease and caused intermittent
deadlocks: the example thread blocked in Playwright while holding
the only connection, and the server sat idle in an open transaction.
Instance Method Summary collapse
- #connection ⇒ Object
-
#lease_connection ⇒ Object
lease_connection/with_connection don't exist before Rails 7.2, so
superisn't always callable -- fall back to the always-available #connection instead of blowing up with a NoMethodError. - #shared_connection ⇒ Object
- #shared_connection=(connection) ⇒ Object
- #with_connection(prevent_permanent_checkout: false) ⇒ Object
Instance Method Details
#connection ⇒ Object
53 54 55 |
# File 'lib/e2e/rails.rb', line 53 def connection E2E::Rails.shared_connection || super end |
#lease_connection ⇒ Object
lease_connection/with_connection don't exist before Rails 7.2, so
super isn't always callable -- fall back to the always-available
#connection instead of blowing up with a NoMethodError.
60 61 62 |
# File 'lib/e2e/rails.rb', line 60 def lease_connection E2E::Rails.shared_connection || (defined?(super) ? super : connection) end |
#shared_connection ⇒ Object
78 79 80 |
# File 'lib/e2e/rails.rb', line 78 def shared_connection E2E::Rails.shared_connection end |
#shared_connection=(connection) ⇒ Object
74 75 76 |
# File 'lib/e2e/rails.rb', line 74 def shared_connection=(connection) E2E::Rails.shared_connection = connection end |
#with_connection(prevent_permanent_checkout: false) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/e2e/rails.rb', line 64 def with_connection(prevent_permanent_checkout: false) if (conn = E2E::Rails.shared_connection) yield conn elsif defined?(super) super else yield connection end end |