aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2016-02-08 05:13:05 +1030
committerMatthew Draper <matthew@trebex.net>2016-02-08 05:30:10 +1030
commitfe7d77cc01ae652a15b2c1896f677a56133bc0f1 (patch)
tree7ffc92f84d3936bc8f5db205c3cc8b93ed0eb61c /activesupport
parent5d9e59131312f83f925e2ce59865bcb537976422 (diff)
downloadrails-fe7d77cc01ae652a15b2c1896f677a56133bc0f1.tar.gz
rails-fe7d77cc01ae652a15b2c1896f677a56133bc0f1.tar.bz2
rails-fe7d77cc01ae652a15b2c1896f677a56133bc0f1.zip
Test the happy path for recursive yields too
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/test/share_lock_test.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/activesupport/test/share_lock_test.rb b/activesupport/test/share_lock_test.rb
index 143e65aa0c..acefa185a8 100644
--- a/activesupport/test/share_lock_test.rb
+++ b/activesupport/test/share_lock_test.rb
@@ -341,6 +341,41 @@ class ShareLockTest < ActiveSupport::TestCase
threads.each(&:kill) if threads
end
+ def test_manual_recursive_yield
+ ready = Concurrent::CyclicBarrier.new(2)
+ done = Concurrent::CyclicBarrier.new(2)
+ do_nesting = Concurrent::CountDownLatch.new
+
+ threads = [
+ Thread.new do
+ @lock.sharing do
+ ready.wait
+ @lock.exclusive(purpose: :x) {}
+ done.wait
+ end
+ end,
+
+ Thread.new do
+ @lock.sharing do
+ @lock.yield_shares(compatible: [:x]) do
+ @lock.sharing do
+ ready.wait
+ do_nesting.wait
+ @lock.yield_shares(compatible: [:x, :y]) do
+ done.wait
+ end
+ end
+ end
+ end
+ end
+ ]
+
+ assert_threads_stuck threads
+ do_nesting.count_down
+
+ assert_threads_not_stuck threads
+ end
+
def test_manual_recursive_yield_cannot_expand_outer_compatible
ready = Concurrent::CyclicBarrier.new(2)
do_compatible_nesting = Concurrent::CountDownLatch.new