@@ -474,12 +474,11 @@ takes your entire test suite to run.
474
474
475
475
The default parallelization method is to fork processes using Ruby's DRb system. The processes
476
476
are forked based on the number of workers provided. The default is 2, but can be changed by the
477
- number passed to the parallelize method. Active Record automatically handles creating and
478
- migrating a new database for each worker to use.
477
+ number passed to the parallelize method.
479
478
480
479
To enable parallelization add the following to your ` test_helper.rb ` :
481
480
482
- ```
481
+ ``` ruby
483
482
class ActiveSupport ::TestCase
484
483
parallelize(workers: 2 )
485
484
end
@@ -489,32 +488,32 @@ The number of workers passed is the number of times the process will be forked.
489
488
parallelize your local test suite differently from your CI, so an environment variable is provided
490
489
to be able to easily change the number of workers a test run should use:
491
490
492
- ```
491
+ ``` bash
493
492
PARALLEL_WORKERS=15 rails test
494
493
```
495
494
496
- When parallelizing tests, Active Record automatically handles creating and migrating a database for each
495
+ When parallelizing tests, Active Record automatically handles creating a database and loading the schema into the database for each
497
496
process. The databases will be suffixed with the number corresponding to the worker. For example, if you
498
497
have 2 workers the tests will create ` test-database-0 ` and ` test-database-1 ` respectively.
499
498
500
499
If the number of workers passed is 1 or fewer the processes will not be forked and the tests will not
501
500
be parallelized and the tests will use the original ` test-database ` database.
502
501
503
- Two hooks are provided, one runs when the process is forked, and one runs before the processes are closed.
502
+ Two hooks are provided, one runs when the process is forked, and one runs before the forked process is closed.
504
503
These can be useful if your app uses multiple databases or perform other tasks that depend on the number of
505
504
workers.
506
505
507
506
The ` parallelize_setup ` method is called right after the processes are forked. The ` parallelize_teardown ` method
508
507
is called right before the processes are closed.
509
508
510
- ```
509
+ ``` ruby
511
510
class ActiveSupport ::TestCase
512
511
parallelize_setup do |worker |
513
512
# setup databases
514
513
end
515
514
516
515
parallelize_teardown do |worker |
517
- # cleanup database
516
+ # cleanup databases
518
517
end
519
518
520
519
parallelize(workers: 2 )
@@ -530,7 +529,7 @@ parallelizer is backed by Minitest's `Parallel::Executor`.
530
529
531
530
To change the parallelization method to use threads over forks put the following in your ` test_helper.rb `
532
531
533
- ```
532
+ ``` ruby
534
533
class ActiveSupport ::TestCase
535
534
parallelize(workers: 2 , with: :threads )
536
535
end
@@ -542,7 +541,7 @@ The number of workers passed to `parallelize` determines the number of threads t
542
541
want to parallelize your local test suite differently from your CI, so an environment variable is provided
543
542
to be able to easily change the number of workers a test run should use:
544
543
545
- ```
544
+ ``` bash
546
545
PARALLEL_WORKERS=15 rails test
547
546
```
548
547
0 commit comments