aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/share_lock_test.rb
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2016-02-01 23:58:36 +1030
committerMatthew Draper <matthew@trebex.net>2016-02-02 03:21:03 +1030
commitf02bd2a92c67f0d4190853521d3580766e829044 (patch)
tree09432835b23706daef64f7ec401baed27d4c5257 /activesupport/test/share_lock_test.rb
parentaeb58ab70470b7f395a1e77b10c9b7a73955dad8 (diff)
downloadrails-f02bd2a92c67f0d4190853521d3580766e829044.tar.gz
rails-f02bd2a92c67f0d4190853521d3580766e829044.tar.bz2
rails-f02bd2a92c67f0d4190853521d3580766e829044.zip
While new sharers are blocked, an existing sharer remains re-entrant
Diffstat (limited to 'activesupport/test/share_lock_test.rb')
-rw-r--r--activesupport/test/share_lock_test.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/activesupport/test/share_lock_test.rb b/activesupport/test/share_lock_test.rb
index 0a5b074bee..3475ee94cd 100644
--- a/activesupport/test/share_lock_test.rb
+++ b/activesupport/test/share_lock_test.rb
@@ -241,6 +241,35 @@ class ShareLockTest < ActiveSupport::TestCase
end
end
+ def test_share_remains_reentrant_ignoring_a_waiting_exclusive
+ with_thread_waiting_in_lock_section(:sharing) do |sharing_thread_release_latch|
+ ready = Concurrent::CyclicBarrier.new(2)
+ attempt_reentrancy = Concurrent::CountDownLatch.new
+
+ sharer = Thread.new do
+ @lock.sharing do
+ ready.wait
+ attempt_reentrancy.wait
+ @lock.sharing {}
+ end
+ end
+
+ exclusive = Thread.new do
+ @lock.sharing do
+ ready.wait
+ @lock.exclusive {}
+ end
+ end
+
+ assert_threads_stuck exclusive
+
+ attempt_reentrancy.count_down
+
+ assert_threads_not_stuck sharer
+ assert_threads_stuck exclusive
+ end
+ end
+
def test_in_shared_section_incompatible_non_upgrading_threads_cannot_preempt_upgrading_threads
scratch_pad = []
scratch_pad_mutex = Mutex.new