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:
parent
c2f4a200e2
commit
87f5e5e28a
|
@ -455,43 +455,63 @@ 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
|
||||||
|
|
||||||
# create a first_thread and let it get into the FIFO queue first
|
begin
|
||||||
first_thread = Thread.new do
|
# create a first_thread and let it get into the FIFO queue first
|
||||||
pool.with_connection { second_thread_done.wait }
|
first_thread = Thread.new do
|
||||||
|
pool.with_connection { second_thread_done.wait }
|
||||||
|
end
|
||||||
|
|
||||||
|
# wait for first_thread to get in queue
|
||||||
|
Thread.pass until pool.num_waiting_in_queue == 1
|
||||||
|
|
||||||
|
# create a different, later thread, that will attempt to do a "group action",
|
||||||
|
# but because of the group action semantics it should be able to preempt the
|
||||||
|
# first_thread when a connection is made available
|
||||||
|
second_thread = Thread.new do
|
||||||
|
pool.send(group_action_method)
|
||||||
|
second_thread_done.set
|
||||||
|
end
|
||||||
|
|
||||||
|
# wait for second_thread to get in queue
|
||||||
|
Thread.pass until pool.num_waiting_in_queue == 2
|
||||||
|
|
||||||
|
# return the only available connection
|
||||||
|
pool.checkin(conn)
|
||||||
|
|
||||||
|
# if the second_thread is not able to preempt the first_thread,
|
||||||
|
# they will temporarily (until either of them timeouts with ConnectionTimeoutError)
|
||||||
|
# deadlock and a join(2) timeout will be reached
|
||||||
|
assert second_thread.join(2), "#{group_action_method} is not able to preempt other waiting threads"
|
||||||
|
|
||||||
|
ensure
|
||||||
|
# post test clean up
|
||||||
|
failed = !second_thread_done.set?
|
||||||
|
|
||||||
|
if failed
|
||||||
|
second_thread_done.set
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
# wait for first_thread to get in queue
|
|
||||||
Thread.pass until pool.num_waiting_in_queue == 1
|
|
||||||
|
|
||||||
# create a different, later thread, that will attempt to do a "group action",
|
|
||||||
# but because of the group action semantics it should be able to preempt the
|
|
||||||
# first_thread when a connection is made available
|
|
||||||
second_thread = Thread.new do
|
|
||||||
pool.send(group_action_method)
|
|
||||||
second_thread_done.count_down
|
|
||||||
end
|
|
||||||
|
|
||||||
# wait for second_thread to get in queue
|
|
||||||
Thread.pass until pool.num_waiting_in_queue == 2
|
|
||||||
|
|
||||||
# return the only available connection
|
|
||||||
pool.checkin(conn)
|
|
||||||
|
|
||||||
# if the second_thread is not able to preempt the first_thread,
|
|
||||||
# they will temporarily (until either of them timeouts with ConnectionTimeoutError)
|
|
||||||
# deadlock and a join(2) timeout will be reached
|
|
||||||
failed = true unless second_thread.join(2)
|
|
||||||
|
|
||||||
#--- post test clean up start
|
|
||||||
second_thread_done.count_down if failed
|
|
||||||
|
|
||||||
first_thread.join
|
|
||||||
second_thread.join
|
|
||||||
#--- post test clean up end
|
|
||||||
|
|
||||||
flunk "#{group_action_method} is not able to preempt other waiting threads" if failed
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue