We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent cc79c2f commit d17861bCopy full SHA for d17861b
library/monitor/synchronize_spec.rb
@@ -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
23
24
25
+ Thread.pass until locked
26
+ thread.raise exc_class, "interrupt"
27
+ thread.value.should == :ok
28
29
30
+end
0 commit comments