Update to ruby/mspec@820486a
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66039 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
047111584f
commit
eae7fbb682
@ -1,26 +1,24 @@
|
|||||||
class BlockingMatcher
|
class BlockingMatcher
|
||||||
def matches?(block)
|
def matches?(block)
|
||||||
started = false
|
t = Thread.new do
|
||||||
blocking = true
|
|
||||||
|
|
||||||
thread = Thread.new do
|
|
||||||
started = true
|
|
||||||
block.call
|
block.call
|
||||||
|
|
||||||
blocking = false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Thread.pass while !started
|
loop do
|
||||||
|
case t.status
|
||||||
# Wait until the Thread status is "sleep" (then it's blocking)
|
when "sleep" # blocked
|
||||||
# or nil (the Thread finished execution, it did not block)
|
t.kill
|
||||||
while status = thread.status and status != "sleep"
|
t.join
|
||||||
Thread.pass
|
return true
|
||||||
|
when false # terminated normally, so never blocked
|
||||||
|
t.join
|
||||||
|
return false
|
||||||
|
when nil # terminated exceptionally
|
||||||
|
t.value
|
||||||
|
else
|
||||||
|
Thread.pass
|
||||||
|
end
|
||||||
end
|
end
|
||||||
thread.kill
|
|
||||||
thread.join
|
|
||||||
|
|
||||||
blocking
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def failure_message
|
def failure_message
|
||||||
@ -33,7 +31,7 @@ class BlockingMatcher
|
|||||||
end
|
end
|
||||||
|
|
||||||
module MSpecMatchers
|
module MSpecMatchers
|
||||||
private def block_caller(timeout = 0.1)
|
private def block_caller
|
||||||
BlockingMatcher.new
|
BlockingMatcher.new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user