diff options
author | eileencodes <eileencodes@gmail.com> | 2017-02-20 13:35:19 -0500 |
---|---|---|
committer | eileencodes <eileencodes@gmail.com> | 2017-02-20 16:31:24 -0500 |
commit | d6466beb9fff9f2ba4f73673e65f087dd6bba488 (patch) | |
tree | 72e63e704e18a4bc37594e5b5d482bcc59754545 /guides/.document | |
parent | 71da39097b67114329be6d8db7fe6911124531af (diff) | |
download | rails-d6466beb9fff9f2ba4f73673e65f087dd6bba488.tar.gz rails-d6466beb9fff9f2ba4f73673e65f087dd6bba488.tar.bz2 rails-d6466beb9fff9f2ba4f73673e65f087dd6bba488.zip |
Ensure test threads share a DB connection
This ensures multiple threads inside a transactional test to see consistent
database state.
When a system test starts Puma spins up one thread and Capybara spins up
another thread. Because of this when tests are run the database cannot
see what was inserted into the database on teardown. This is because
there are two threads using two different connections.
This change uses the statement cache to lock the threads to using a
single connection ID instead of each not being able to see each other.
This code only runs in the fixture setup and teardown so it does not
affect real production databases.
When a transaction is opened we set `lock_thread` to `Thread.current` so
we can keep track of which connection the thread is using. When we
rollback the transaction we unlock the thread and then there will be no
left-over data in the database because the transaction will roll back
the correct connections.
[ Eileen M. Uchitelle, Matthew Draper ]
Diffstat (limited to 'guides/.document')
0 files changed, 0 insertions, 0 deletions