mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Added parallell testing of transactions section
Based on https://github.com/rails/rails/issues/38578, it would be nice to have some information on transactions in test cases
This commit is contained in:
parent
c86750c377
commit
926365b355
1 changed files with 26 additions and 0 deletions
|
@ -545,6 +545,32 @@ to be able to easily change the number of workers a test run should use:
|
||||||
PARALLEL_WORKERS=15 rails test
|
PARALLEL_WORKERS=15 rails test
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Testing Parallel Transactions
|
||||||
|
|
||||||
|
Rails automatically wraps any test case in a database transaction that is rolled
|
||||||
|
back after the test completes. This makes test cases independent of each other
|
||||||
|
and changes to the database are only visible within a single test.
|
||||||
|
|
||||||
|
When you want to test code that runs parallel transactions in threads,
|
||||||
|
transactions can block each other because they are already nested under the test
|
||||||
|
transaction.
|
||||||
|
|
||||||
|
You can disable transactions in a test case class by setting
|
||||||
|
`self.use_transactional_tests = false`:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
class WorkerTest < ActiveSupport::TestCase
|
||||||
|
self.use_transactional_tests = false
|
||||||
|
|
||||||
|
test "parallel transactions" do
|
||||||
|
# start some threads that create transactions
|
||||||
|
end
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
NOTE: With disabled transactional tests, you have to clean up any data tests
|
||||||
|
create as changes are not automatically rolled back after the test completes.
|
||||||
|
|
||||||
The Test Database
|
The Test Database
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue