2018-03-04 10:09:32 -05:00
|
|
|
require_relative '../../spec_helper'
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
describe "Mutex#lock" do
|
|
|
|
before :each do
|
|
|
|
ScratchPad.clear
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns self" do
|
|
|
|
m = Mutex.new
|
|
|
|
m.lock.should == m
|
|
|
|
m.unlock
|
|
|
|
end
|
|
|
|
|
2018-11-27 15:38:57 -05:00
|
|
|
it "blocks the caller if already locked" do
|
2017-05-07 08:04:49 -04:00
|
|
|
m = Mutex.new
|
|
|
|
m.lock
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { m.lock }.should block_caller
|
2018-11-27 15:38:57 -05:00
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
|
2018-11-27 15:38:57 -05:00
|
|
|
it "does not block the caller if not locked" do
|
|
|
|
m = Mutex.new
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { m.lock }.should_not block_caller
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# Unable to find a specific ticket but behavior change may be
|
|
|
|
# related to this ML thread.
|
|
|
|
it "raises a ThreadError when used recursively" do
|
|
|
|
m = Mutex.new
|
2017-10-28 11:15:48 -04:00
|
|
|
m.lock
|
|
|
|
-> {
|
2017-05-07 08:04:49 -04:00
|
|
|
m.lock
|
2017-10-28 11:15:48 -04:00
|
|
|
}.should raise_error(ThreadError)
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
end
|