11require "cases/helper"
2- require 'active_support/concurrency/latch '
2+ require 'concurrent/atomics '
33
44module ActiveRecord
55 module ConnectionAdapters
@@ -133,15 +133,15 @@ def test_reap_and_active
133133 end
134134
135135 def test_reap_inactive
136- ready = ActiveSupport :: Concurrency :: Latch . new
136+ ready = Concurrent :: CountDownLatch . new
137137 @pool . checkout
138138 child = Thread . new do
139139 @pool . checkout
140140 @pool . checkout
141- ready . release
141+ ready . count_down
142142 Thread . stop
143143 end
144- ready . await
144+ ready . wait
145145
146146 assert_equal 3 , active_connections ( @pool ) . size
147147
@@ -360,13 +360,13 @@ def test_pool_sets_connection_schema_cache
360360 def test_concurrent_connection_establishment
361361 assert_operator @pool . connections . size , :<= , 1
362362
363- all_threads_in_new_connection = ActiveSupport :: Concurrency :: Latch . new ( @pool . size - @pool . connections . size )
364- all_go = ActiveSupport :: Concurrency :: Latch . new
363+ all_threads_in_new_connection = Concurrent :: CountDownLatch . new ( @pool . size - @pool . connections . size )
364+ all_go = Concurrent :: CountDownLatch . new
365365
366366 @pool . singleton_class . class_eval do
367367 define_method ( :new_connection ) do
368- all_threads_in_new_connection . release
369- all_go . await
368+ all_threads_in_new_connection . count_down
369+ all_go . wait
370370 super ( )
371371 end
372372 end
@@ -381,14 +381,14 @@ def test_concurrent_connection_establishment
381381 # the kernel of the whole test is here, everything else is just scaffolding,
382382 # this latch will not be released unless conn. pool allows for concurrent
383383 # connection creation
384- all_threads_in_new_connection . await
384+ all_threads_in_new_connection . wait
385385 end
386386 rescue Timeout ::Error
387387 flunk 'pool unable to establish connections concurrently or implementation has ' <<
388388 'changed, this test then needs to patch a different :new_connection method'
389389 ensure
390390 # clean up the threads
391- all_go . release
391+ all_go . count_down
392392 connecting_threads . map ( &:join )
393393 end
394394 end
@@ -441,11 +441,11 @@ def test_disconnect_and_clear_reloadable_connections_are_able_to_preempt_other_w
441441 with_single_connection_pool do |pool |
442442 [ :disconnect , :disconnect! , :clear_reloadable_connections , :clear_reloadable_connections! ] . each do |group_action_method |
443443 conn = pool . connection # drain the only available connection
444- second_thread_done = ActiveSupport :: Concurrency :: Latch . new
444+ second_thread_done = Concurrent :: CountDownLatch . new
445445
446446 # create a first_thread and let it get into the FIFO queue first
447447 first_thread = Thread . new do
448- pool . with_connection { second_thread_done . await }
448+ pool . with_connection { second_thread_done . wait }
449449 end
450450
451451 # wait for first_thread to get in queue
@@ -456,7 +456,7 @@ def test_disconnect_and_clear_reloadable_connections_are_able_to_preempt_other_w
456456 # first_thread when a connection is made available
457457 second_thread = Thread . new do
458458 pool . send ( group_action_method )
459- second_thread_done . release
459+ second_thread_done . count_down
460460 end
461461
462462 # wait for second_thread to get in queue
@@ -471,7 +471,7 @@ def test_disconnect_and_clear_reloadable_connections_are_able_to_preempt_other_w
471471 failed = true unless second_thread . join ( 2 )
472472
473473 #--- post test clean up start
474- second_thread_done . release if failed
474+ second_thread_done . count_down if failed
475475
476476 # after `pool.disconnect()` the first thread will be left stuck in queue, no need to wait for
477477 # it to timeout with ConnectionTimeoutError
0 commit comments