Skip to content

Commit d17861b

Browse files
committed
Fix usage of Thread.handle_interrupt in MonitorMixin#mon_synchronize
* See https://bugs.ruby-lang.org/issues/17669 and https://github.com/ruby/monitor/issues/2 and jruby/jruby#6526
1 parent cc79c2f commit d17861b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

library/monitor/synchronize_spec.rb

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require_relative '../../spec_helper'
2+
require 'monitor'
3+
4+
describe "Monitor#synchronize" do
5+
it "unlocks after return, even if it was interrupted by Thread#raise" do
6+
exc_class = Class.new(RuntimeError)
7+
8+
monitor = Monitor.new
9+
10.times do
10+
locked = false
11+
12+
thread = Thread.new do
13+
begin
14+
monitor.synchronize do
15+
locked = true
16+
# Do not wait here, we are trying to interrupt the ensure part of #synchronize
17+
end
18+
sleep # wait for exception if it did not happen yet
19+
rescue exc_class
20+
monitor.should_not.mon_locked?
21+
:ok
22+
end
23+
end
24+
25+
Thread.pass until locked
26+
thread.raise exc_class, "interrupt"
27+
thread.value.should == :ok
28+
end
29+
end
30+
end

0 commit comments

Comments
 (0)