Skip to content

Commit 22b86f3

Browse files
authored
Merge pull request rails#54985 from rails/add-public-api-for-before_fork_hook
Add public API for `before_fork_hook` in parallel testing
2 parents 0367cbf + 5696682 commit 22b86f3

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

activesupport/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
* Add public API for `before_fork_hook` in parallel testing.
2+
3+
Introduces a public API for calling the before fork hooks implemented by parallel testing.
4+
5+
```ruby
6+
parallelize_before_fork do
7+
# perform an action before test processes are forked
8+
end
9+
```
10+
11+
*Eileen M. Uchitelle*
12+
113
* Implement ability to skip creating parallel testing databases.
214

315
With parallel testing, Rails will create a database per process. If this isn't

activesupport/lib/active_support/test_case.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,21 @@ def parallelize(workers: :number_of_processors, with: :processes, threshold: Act
103103
Minitest.parallel_executor = ActiveSupport::Testing::ParallelizeExecutor.new(size: workers, with: with, threshold: threshold)
104104
end
105105

106-
# Set up hook for parallel testing. This can be used if you have multiple
106+
# Before fork hook for parallel testing. This can be used to run anything
107+
# before the processes are forked.
108+
#
109+
# In your +test_helper.rb+ add the following:
110+
#
111+
# class ActiveSupport::TestCase
112+
# parallelize_before_fork do
113+
# # run this before fork
114+
# end
115+
# end
116+
def parallelize_before_fork(&block)
117+
ActiveSupport::Testing::Parallelization.before_fork_hook(&block)
118+
end
119+
120+
# Setup hook for parallel testing. This can be used if you have multiple
107121
# databases or any behavior that needs to be run after the process is forked
108122
# but before the tests run.
109123
#

0 commit comments

Comments
 (0)