File tree Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -301,9 +301,8 @@ def process(name)
301
301
error = e
302
302
end
303
303
ensure
304
- # Ensure we clean up any thread locals we copied so that the thread can reused.
305
304
ActiveSupport ::IsolatedExecutionState . clear
306
- locals . each { | k , _ | t2 [ k ] = nil }
305
+ clean_up_thread_locals ( locals , t2 )
307
306
308
307
@_response . commit!
309
308
end
@@ -377,6 +376,11 @@ def new_controller_thread # :nodoc:
377
376
end
378
377
end
379
378
379
+ # Ensure we clean up any thread locals we copied so that the thread can reused.
380
+ def clean_up_thread_locals ( locals , thread ) # :nodoc:
381
+ locals . each { |k , _ | thread [ k ] = nil }
382
+ end
383
+
380
384
def self . live_thread_pool_executor
381
385
@live_thread_pool_executor ||= Concurrent ::CachedThreadPool . new ( name : "action_controller.live" )
382
386
end
Original file line number Diff line number Diff line change @@ -29,6 +29,14 @@ def new_controller_thread # :nodoc:
29
29
yield
30
30
end
31
31
32
+ # Because of the above, we need to prevent the clearing of thread locals, since
33
+ # no new thread is actually spawned in the test environment.
34
+ alias_method :original_clean_up_thread_locals , :clean_up_thread_locals
35
+
36
+ silence_redefinition_of_method :clean_up_thread_locals
37
+ def clean_up_thread_locals ( *args ) # :nodoc:
38
+ end
39
+
32
40
# Avoid a deadlock from the queue filling up
33
41
Buffer . queue_size = nil
34
42
end
Original file line number Diff line number Diff line change @@ -360,6 +360,10 @@ def setup
360
360
def @controller . new_controller_thread ( &block )
361
361
original_new_controller_thread ( &block )
362
362
end
363
+
364
+ def @controller . clean_up_thread_locals ( *args )
365
+ original_clean_up_thread_locals ( *args )
366
+ end
363
367
end
364
368
365
369
def test_set_cookie
@@ -674,7 +678,7 @@ def greet
674
678
tests TestController
675
679
676
680
def test_thread_locals_do_not_get_reset_in_test_environment
677
- Thread . current [ :setting ] = "aaron"
681
+ Thread . current [ :setting ] = "aaron"
678
682
679
683
get :greet
680
684
You can’t perform that action at this time.
0 commit comments