1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Make the test that seems to be getting stuck noisier

I assume it's upset because of the change in d314646c96,
but I don't yet understand why.
This commit is contained in:
Matthew Draper 2016-11-26 15:35:23 +10:30
parent c2f4a200e2
commit 87f5e5e28a

View file

@ -455,8 +455,9 @@ module ActiveRecord
with_single_connection_pool do |pool| with_single_connection_pool do |pool|
[:disconnect, :disconnect!, :clear_reloadable_connections, :clear_reloadable_connections!].each do |group_action_method| [:disconnect, :disconnect!, :clear_reloadable_connections, :clear_reloadable_connections!].each do |group_action_method|
conn = pool.connection # drain the only available connection conn = pool.connection # drain the only available connection
second_thread_done = Concurrent::CountDownLatch.new second_thread_done = Concurrent::Event.new
begin
# create a first_thread and let it get into the FIFO queue first # create a first_thread and let it get into the FIFO queue first
first_thread = Thread.new do first_thread = Thread.new do
pool.with_connection { second_thread_done.wait } pool.with_connection { second_thread_done.wait }
@ -470,7 +471,7 @@ module ActiveRecord
# first_thread when a connection is made available # first_thread when a connection is made available
second_thread = Thread.new do second_thread = Thread.new do
pool.send(group_action_method) pool.send(group_action_method)
second_thread_done.count_down second_thread_done.set
end end
# wait for second_thread to get in queue # wait for second_thread to get in queue
@ -482,16 +483,35 @@ module ActiveRecord
# if the second_thread is not able to preempt the first_thread, # if the second_thread is not able to preempt the first_thread,
# they will temporarily (until either of them timeouts with ConnectionTimeoutError) # they will temporarily (until either of them timeouts with ConnectionTimeoutError)
# deadlock and a join(2) timeout will be reached # deadlock and a join(2) timeout will be reached
failed = true unless second_thread.join(2) assert second_thread.join(2), "#{group_action_method} is not able to preempt other waiting threads"
#--- post test clean up start ensure
second_thread_done.count_down if failed # post test clean up
failed = !second_thread_done.set?
first_thread.join if failed
second_thread.join second_thread_done.set
#--- post test clean up end
flunk "#{group_action_method} is not able to preempt other waiting threads" if failed puts
puts ">>> test_disconnect_and_clear_reloadable_connections_are_able_to_preempt_other_waiting_threads / #{group_action_method}"
p [first_thread, second_thread]
p pool.stat
p pool.connections.map(&:owner)
first_thread.join(2)
second_thread.join(2)
puts '---'
p [first_thread, second_thread]
p pool.stat
p pool.connections.map(&:owner)
puts '<<<'
puts
end
first_thread.join(10) || raise("first_thread got stuck")
second_thread.join(10) || raise("second_thread got stuck")
end
end end
end end
end end