File tree Expand file tree Collapse file tree 4 files changed +29
-0
lines changed
lib/active_support/testing Expand file tree Collapse file tree 4 files changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ * Introduce a before-fork hook in ` ActiveSupport::Testing::Parallelization ` to clear existing
2
+ connections, to avoid fork-safety issues with the mysql2 adapter.
3
+
4
+ Fixes #41776
5
+
6
+ * Mike Dalessio* , * Donal McBreen*
7
+
1
8
* PoolConfig no longer keeps a reference to the connection class.
2
9
3
10
Keeping a reference to the class caused subtle issues when combined with reloading in
Original file line number Diff line number Diff line change 4
4
5
5
module ActiveRecord
6
6
module TestDatabases # :nodoc:
7
+ ActiveSupport ::Testing ::Parallelization . before_fork_hook do
8
+ ActiveRecord ::Base . connection_handler . clear_all_connections!
9
+ end
10
+
7
11
ActiveSupport ::Testing ::Parallelization . after_fork_hook do |i |
8
12
create_and_load_schema ( i , env_name : ActiveRecord ::ConnectionHandling ::DEFAULT_ENV . call )
9
13
end
Original file line number Diff line number Diff line change
1
+ * ` ActiveSupport::Testing::Parallelization.before_fork_hook ` allows declaration of callbacks that
2
+ are invoked immediately before forking test workers.
3
+
4
+ * Mike Dalessio*
5
+
1
6
* Allow the ` #freeze_time ` testing helper to accept a date or time argument.
2
7
3
8
``` ruby
Original file line number Diff line number Diff line change 9
9
module ActiveSupport
10
10
module Testing
11
11
class Parallelization # :nodoc:
12
+ @@before_fork_hooks = [ ]
13
+
14
+ def self . before_fork_hook ( &blk )
15
+ @@before_fork_hooks << blk
16
+ end
17
+
18
+ cattr_reader :before_fork_hooks
19
+
12
20
@@after_fork_hooks = [ ]
13
21
14
22
def self . after_fork_hook ( &blk )
@@ -32,7 +40,12 @@ def initialize(worker_count)
32
40
@url = DRb . start_service ( "drbunix:" , @queue_server ) . uri
33
41
end
34
42
43
+ def before_fork
44
+ Parallelization . before_fork_hooks . each ( &:cb )
45
+ end
46
+
35
47
def start
48
+ before_fork
36
49
@worker_pool = @worker_count . times . map do |worker |
37
50
Worker . new ( worker , @url ) . start
38
51
end
You can’t perform that action at this time.
0 commit comments