diff options
author | Matthew Draper <matthew@trebex.net> | 2015-07-21 11:48:21 +0930 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2015-07-21 12:03:38 +0930 |
commit | e9020ac4310d1b190619769a8a621935d4efc812 (patch) | |
tree | f31c0d6537e956f292c45d09fff886aca812ab41 /activesupport/test | |
parent | 4c54b2a9a012296709de5283eada03470d581dc9 (diff) | |
download | rails-e9020ac4310d1b190619769a8a621935d4efc812.tar.gz rails-e9020ac4310d1b190619769a8a621935d4efc812.tar.bz2 rails-e9020ac4310d1b190619769a8a621935d4efc812.zip |
Handle thread death during lock acquisition
Specifically, clean up if the thread is killed while it's blocked
awaiting the lock... if we get killed on some other arbitrary line, the
result remains quite undefined.
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/share_lock_test.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/activesupport/test/share_lock_test.rb b/activesupport/test/share_lock_test.rb index efd840be79..4c0d23784e 100644 --- a/activesupport/test/share_lock_test.rb +++ b/activesupport/test/share_lock_test.rb @@ -81,6 +81,27 @@ class ShareLockTest < ActiveSupport::TestCase end end + def test_killed_thread_loses_lock + with_thread_waiting_in_lock_section(:sharing) do |sharing_thread_release_latch| + thread = Thread.new do + @lock.sharing do + @lock.exclusive {} + end + end + + assert_threads_stuck thread + thread.kill + + sharing_thread_release_latch.count_down + + thread = Thread.new do + @lock.exclusive {} + end + + assert_threads_not_stuck thread + end + end + def test_exclusive_conflicting_purpose [true, false].each do |use_upgrading| with_thread_waiting_in_lock_section(:sharing) do |sharing_thread_release_latch| |