aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/scoping
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2017-01-02 05:04:17 +1030
committerMatthew Draper <matthew@trebex.net>2017-01-02 05:04:17 +1030
commitdae525eec8062bfbbe39141de448053b127d4756 (patch)
tree3409363e6ecf912b94a286ec3f93102c1c705cf8 /activerecord/test/cases/scoping
parent19deeb08df6279a9cbf0c65548641776c0451471 (diff)
downloadrails-dae525eec8062bfbbe39141de448053b127d4756.tar.gz
rails-dae525eec8062bfbbe39141de448053b127d4756.tar.bz2
rails-dae525eec8062bfbbe39141de448053b127d4756.zip
Replace sleep with synchronization
Diffstat (limited to 'activerecord/test/cases/scoping')
-rw-r--r--activerecord/test/cases/scoping/default_scoping_test.rb8
1 files changed, 7 insertions, 1 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