aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2016-02-05 11:42:06 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2016-02-05 11:42:15 -0800
commita640da454fdb9cd8806a1b6bd98c2da93f1b53b9 (patch)
treea69eff36c33ece5879267886ec20a7a8263fa2ba /actionpack/test
parentf4f998d60d0d095c7d49a26b6030bee4cf92a5d3 (diff)
downloadrails-a640da454fdb9cd8806a1b6bd98c2da93f1b53b9.tar.gz
rails-a640da454fdb9cd8806a1b6bd98c2da93f1b53b9.tar.bz2
rails-a640da454fdb9cd8806a1b6bd98c2da93f1b53b9.zip
disable controller / view thread spawning in tests
Tests can (and do) access the database from the main thread. In this case they were starting a transaction, then making a request. The request would create a new thread, which would allocate a new database connection. Since the main thread started a transaction that contains data that the new thread wants to see, the new thread would not see it due to data visibility from transactions. Spawning the new thread in production is fine because middleware should not be doing database manipulation similar to the test harness. Before 603fe20c it was possible to set the database connection id based on a thread local, but 603fe20c changes the connection lookup code to never look at the "connection id" but only at the thread object itself. Without that indirection, we can't force threads to use the same connection pool as another thread. Fixes #23483
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/controller/live_stream_test.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/actionpack/test/controller/live_stream_test.rb b/actionpack/test/controller/live_stream_test.rb
index 2ef9734269..0c3884cd38 100644
--- a/actionpack/test/controller/live_stream_test.rb
+++ b/actionpack/test/controller/live_stream_test.rb
@@ -152,7 +152,6 @@ module ActionController
def thread_locals
tc.assert_equal 'aaron', Thread.current[:setting]
- tc.assert_not_equal Thread.current.object_id, Thread.current[:originating_thread]
response.headers['Content-Type'] = 'text/event-stream'
%w{ hello world }.each do |word|
@@ -261,6 +260,14 @@ module ActionController
end
end
+ def setup
+ super
+
+ def @controller.new_controller_thread
+ Thread.new { yield }
+ end
+ end
+
def test_set_cookie
get :set_cookie
assert_equal({'hello' => 'world'}, @response.cookies)