diff options
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG.md | 5 | ||||
-rw-r--r-- | activerecord/test/cases/base_test.rb | 14 | ||||
-rw-r--r-- | activerecord/test/cases/connection_pool_test.rb | 28 |
3 files changed, 26 insertions, 21 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index e4a6734009..e3ad9ff3b1 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,8 @@ +* Replaced `ActiveSupport::Concurrency::Latch` with `Concurrent::CountDownLatch` + from the concurrent-ruby gem. + + *Jerry D'Antonio* + * Fix through associations using scopes having the scope merged multiple times. diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 31c31e4329..382adbbdc7 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- require "cases/helper" -require 'active_support/concurrency/latch' require 'models/post' require 'models/author' require 'models/topic' @@ -29,6 +28,7 @@ require 'models/bird' require 'models/car' require 'models/bulb' require 'rexml/document' +require 'concurrent/atomics' class FirstAbstractClass < ActiveRecord::Base self.abstract_class = true @@ -1506,20 +1506,20 @@ class BasicsTest < ActiveRecord::TestCase orig_handler = klass.connection_handler new_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new after_handler = nil - latch1 = ActiveSupport::Concurrency::Latch.new - latch2 = ActiveSupport::Concurrency::Latch.new + latch1 = Concurrent::CountDownLatch.new + latch2 = Concurrent::CountDownLatch.new t = Thread.new do klass.connection_handler = new_handler - latch1.release - latch2.await + latch1.count_down + latch2.wait after_handler = klass.connection_handler end - latch1.await + latch1.wait klass.connection_handler = orig_handler - latch2.release + latch2.count_down t.join assert_equal after_handler, new_handler diff --git a/activerecord/test/cases/connection_pool_test.rb b/activerecord/test/cases/connection_pool_test.rb index c905772193..7ef5c93a48 100644 --- a/activerecord/test/cases/connection_pool_test.rb +++ b/activerecord/test/cases/connection_pool_test.rb @@ -1,5 +1,5 @@ require "cases/helper" -require 'active_support/concurrency/latch' +require 'concurrent/atomics' module ActiveRecord module ConnectionAdapters @@ -133,15 +133,15 @@ module ActiveRecord end def test_reap_inactive - ready = ActiveSupport::Concurrency::Latch.new + ready = Concurrent::CountDownLatch.new @pool.checkout child = Thread.new do @pool.checkout @pool.checkout - ready.release + ready.count_down Thread.stop end - ready.await + ready.wait assert_equal 3, active_connections(@pool).size @@ -360,13 +360,13 @@ module ActiveRecord def test_concurrent_connection_establishment assert_operator @pool.connections.size, :<=, 1 - all_threads_in_new_connection = ActiveSupport::Concurrency::Latch.new(@pool.size - @pool.connections.size) - all_go = ActiveSupport::Concurrency::Latch.new + all_threads_in_new_connection = Concurrent::CountDownLatch.new(@pool.size - @pool.connections.size) + all_go = Concurrent::CountDownLatch.new @pool.singleton_class.class_eval do define_method(:new_connection) do - all_threads_in_new_connection.release - all_go.await + all_threads_in_new_connection.count_down + all_go.wait super() end end @@ -381,14 +381,14 @@ module ActiveRecord # the kernel of the whole test is here, everything else is just scaffolding, # this latch will not be released unless conn. pool allows for concurrent # connection creation - all_threads_in_new_connection.await + all_threads_in_new_connection.wait end rescue Timeout::Error flunk 'pool unable to establish connections concurrently or implementation has ' << 'changed, this test then needs to patch a different :new_connection method' ensure # clean up the threads - all_go.release + all_go.count_down connecting_threads.map(&:join) end end @@ -441,11 +441,11 @@ module ActiveRecord with_single_connection_pool do |pool| [:disconnect, :disconnect!, :clear_reloadable_connections, :clear_reloadable_connections!].each do |group_action_method| conn = pool.connection # drain the only available connection - second_thread_done = ActiveSupport::Concurrency::Latch.new + second_thread_done = Concurrent::CountDownLatch.new # create a first_thread and let it get into the FIFO queue first first_thread = Thread.new do - pool.with_connection { second_thread_done.await } + pool.with_connection { second_thread_done.wait } end # wait for first_thread to get in queue @@ -456,7 +456,7 @@ module ActiveRecord # first_thread when a connection is made available second_thread = Thread.new do pool.send(group_action_method) - second_thread_done.release + second_thread_done.count_down end # wait for second_thread to get in queue @@ -471,7 +471,7 @@ module ActiveRecord failed = true unless second_thread.join(2) #--- post test clean up start - second_thread_done.release if failed + second_thread_done.count_down if failed # after `pool.disconnect()` the first thread will be left stuck in queue, no need to wait for # it to timeout with ConnectionTimeoutError |