summaryrefslogtreecommitdiff
path: root/test/monitor
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2019-11-12 10:02:47 +0900
committerKoichi Sasada <ko1@atdot.net>2019-11-12 10:07:45 +0900
commitfd6445b7e8bab9d340be6f76688a8b96f1b52029 (patch)
treef68a2f6702d897e7fb64a04ea2e9e68b43031a53 /test/monitor
parentfef4370b409c990228cded2c425a6afb3bec2906 (diff)
Monitor#exit: check monitor ownership.
Monitor#exit should be called by only onwer Thread. However, there is not check for it.
Diffstat (limited to 'test/monitor')
-rw-r--r--test/monitor/test_monitor.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/monitor/test_monitor.rb b/test/monitor/test_monitor.rb
index 49c34e0..950db91 100644
--- a/test/monitor/test_monitor.rb
+++ b/test/monitor/test_monitor.rb
@@ -35,6 +35,29 @@ class TestMonitor < Test::Unit::TestCase
assert_equal((1..10).to_a, ary)
end
+ def test_exit
+ m = Monitor.new
+ m.enter
+ assert_equal true, m.mon_owned?
+ m.exit
+ assert_equal false, m.mon_owned?
+
+ assert_raise ThreadError do
+ m.exit
+ end
+
+ assert_equal false, m.mon_owned?
+
+ m.enter
+ Thread.new{
+ assert_raise(ThreadError) do
+ m.exit
+ end
+ }.join
+ assert_equal true, m.mon_owned?
+ m.exit
+ end
+
def test_enter_second_after_killed_thread
th = Thread.start {
@monitor.enter