diff options
author | Matthew Draper <matthew@trebex.net> | 2017-01-02 05:04:17 +1030 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2017-01-02 05:04:17 +1030 |
commit | dae525eec8062bfbbe39141de448053b127d4756 (patch) | |
tree | 3409363e6ecf912b94a286ec3f93102c1c705cf8 | |
parent | 19deeb08df6279a9cbf0c65548641776c0451471 (diff) | |
download | rails-dae525eec8062bfbbe39141de448053b127d4756.tar.gz rails-dae525eec8062bfbbe39141de448053b127d4756.tar.bz2 rails-dae525eec8062bfbbe39141de448053b127d4756.zip |
Replace sleep with synchronization
-rw-r--r-- | activerecord/test/cases/scoping/default_scoping_test.rb | 8 | ||||
-rw-r--r-- | activerecord/test/models/developer.rb | 2 |
2 files changed, 8 insertions, 2 deletions
diff --git a/activerecord/test/cases/scoping/default_scoping_test.rb b/activerecord/test/cases/scoping/default_scoping_test.rb index b408a6000b..3a04f4bf7d 100644 --- a/activerecord/test/cases/scoping/default_scoping_test.rb +++ b/activerecord/test/cases/scoping/default_scoping_test.rb @@ -5,6 +5,7 @@ require "models/developer" require "models/computer" require "models/vehicle" require "models/cat" +require "concurrent/atomic/cyclic_barrier" class DefaultScopingTest < ActiveRecord::TestCase fixtures :developers, :posts, :comments @@ -437,12 +438,17 @@ class DefaultScopingTest < ActiveRecord::TestCase threads = [] assert_not_equal 1, ThreadsafeDeveloper.unscoped.count + barrier_1 = Concurrent::CyclicBarrier.new(2) + barrier_2 = Concurrent::CyclicBarrier.new(2) + threads << Thread.new do - Thread.current[:long_default_scope] = true + Thread.current[:default_scope_delay] = -> { barrier_1.wait; barrier_2.wait } assert_equal 1, ThreadsafeDeveloper.all.to_a.count ThreadsafeDeveloper.connection.close end threads << Thread.new do + Thread.current[:default_scope_delay] = -> { barrier_2.wait } + barrier_1.wait assert_equal 1, ThreadsafeDeveloper.all.to_a.count ThreadsafeDeveloper.connection.close end diff --git a/activerecord/test/models/developer.rb b/activerecord/test/models/developer.rb index 5ca1d37f6d..ea4f719517 100644 --- a/activerecord/test/models/developer.rb +++ b/activerecord/test/models/developer.rb @@ -251,7 +251,7 @@ class ThreadsafeDeveloper < ActiveRecord::Base self.table_name = "developers" def self.default_scope - sleep 0.05 if Thread.current[:long_default_scope] + Thread.current[:default_scope_delay].call limit(1) end end |