4
require 'puppet/agent/locker'
7
include Puppet::Agent::Locker
10
describe Puppet::Agent::Locker do
12
@locker = LockerTester.new
13
@locker.stubs(:lockfile_path).returns "/my/lock"
16
it "should use a Pidlock instance as its lockfile" do
17
@locker.lockfile.should be_instance_of(Puppet::Util::Pidlock)
20
it "should use 'lockfile_path' to determine its lockfile path" do
21
@locker.expects(:lockfile_path).returns "/my/lock"
22
lock = Puppet::Util::Pidlock.new("/my/lock")
23
Puppet::Util::Pidlock.expects(:new).with("/my/lock").returns lock
28
it "should reuse the same lock file each time" do
29
@locker.lockfile.should equal(@locker.lockfile)
32
it "should have a method that yields when a lock is attained" do
33
@locker.lockfile.expects(:lock).returns true
39
yielded.should be_true
42
it "should return true when the lock method successfully locked" do
43
@locker.lockfile.expects(:lock).returns true
45
@locker.lock {}.should be_true
48
it "should return true when the lock method does not receive the lock" do
49
@locker.lockfile.expects(:lock).returns false
51
@locker.lock {}.should be_false
54
it "should not yield when the lock method does not receive the lock" do
55
@locker.lockfile.expects(:lock).returns false
58
@locker.lock { yielded = true }
59
yielded.should be_false
62
it "should not unlock when a lock was not received" do
63
@locker.lockfile.expects(:lock).returns false
64
@locker.lockfile.expects(:unlock).never
69
it "should unlock after yielding upon obtaining a lock" do
70
@locker.lockfile.stubs(:lock).returns true
71
@locker.lockfile.expects(:unlock)
76
it "should unlock after yielding upon obtaining a lock, even if the block throws an exception" do
77
@locker.lockfile.stubs(:lock).returns true
78
@locker.lockfile.expects(:unlock)
80
lambda { @locker.lock { raise "foo" } }.should raise_error(RuntimeError)
83
it "should be considered running if the lockfile is locked" do
84
@locker.lockfile.expects(:locked?).returns true
85
@locker.should be_running