Skip to content

Commit 6ca6478

Browse files
authored
Merge pull request rails#34596 from bogdanvlviv/imporve-parallel-testing-guide
Improve parallel testing guide [ci skip]
2 parents e167818 + 4973a76 commit 6ca6478

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

guides/source/testing.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,11 @@ takes your entire test suite to run.
474474

475475
The default parallelization method is to fork processes using Ruby's DRb system. The processes
476476
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.
479478

480479
To enable parallelization add the following to your `test_helper.rb`:
481480

482-
```
481+
```ruby
483482
class ActiveSupport::TestCase
484483
parallelize(workers: 2)
485484
end
@@ -489,32 +488,32 @@ The number of workers passed is the number of times the process will be forked.
489488
parallelize your local test suite differently from your CI, so an environment variable is provided
490489
to be able to easily change the number of workers a test run should use:
491490

492-
```
491+
```bash
493492
PARALLEL_WORKERS=15 rails test
494493
```
495494

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
497496
process. The databases will be suffixed with the number corresponding to the worker. For example, if you
498497
have 2 workers the tests will create `test-database-0` and `test-database-1` respectively.
499498

500499
If the number of workers passed is 1 or fewer the processes will not be forked and the tests will not
501500
be parallelized and the tests will use the original `test-database` database.
502501

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.
504503
These can be useful if your app uses multiple databases or perform other tasks that depend on the number of
505504
workers.
506505

507506
The `parallelize_setup` method is called right after the processes are forked. The `parallelize_teardown` method
508507
is called right before the processes are closed.
509508

510-
```
509+
```ruby
511510
class ActiveSupport::TestCase
512511
parallelize_setup do |worker|
513512
# setup databases
514513
end
515514

516515
parallelize_teardown do |worker|
517-
# cleanup database
516+
# cleanup databases
518517
end
519518

520519
parallelize(workers: 2)
@@ -530,7 +529,7 @@ parallelizer is backed by Minitest's `Parallel::Executor`.
530529

531530
To change the parallelization method to use threads over forks put the following in your `test_helper.rb`
532531

533-
```
532+
```ruby
534533
class ActiveSupport::TestCase
535534
parallelize(workers: 2, with: :threads)
536535
end
@@ -542,7 +541,7 @@ The number of workers passed to `parallelize` determines the number of threads t
542541
want to parallelize your local test suite differently from your CI, so an environment variable is provided
543542
to be able to easily change the number of workers a test run should use:
544543

545-
```
544+
```bash
546545
PARALLEL_WORKERS=15 rails test
547546
```
548547

0 commit comments

Comments
 (0)