File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -545,6 +545,32 @@ to be able to easily change the number of workers a test run should use:
545
545
PARALLEL_WORKERS=15 rails test
546
546
```
547
547
548
+ ### Testing Parallel Transactions
549
+
550
+ Rails automatically wraps any test case in a database transaction that is rolled
551
+ back after the test completes. This makes test cases independent of each other
552
+ and changes to the database are only visible within a single test.
553
+
554
+ When you want to test code that runs parallel transactions in threads,
555
+ transactions can block each other because they are already nested under the test
556
+ transaction.
557
+
558
+ You can disable transactions in a test case class by setting
559
+ ` self.use_transactional_tests = false ` :
560
+
561
+ ``` ruby
562
+ class WorkerTest < ActiveSupport ::TestCase
563
+ self .use_transactional_tests = false
564
+
565
+ test " parallel transactions" do
566
+ # start some threads that create transactions
567
+ end
568
+ end
569
+ ```
570
+
571
+ NOTE: With disabled transactional tests, you have to clean up any data tests
572
+ create as changes are not automatically rolled back after the test completes.
573
+
548
574
The Test Database
549
575
-----------------
550
576
You can’t perform that action at this time.
0 commit comments