3
require File.dirname(__FILE__) + '/../../spec_helper'
5
require 'puppet/agent/locker'
8
include Puppet::Agent::Locker
11
describe Puppet::Agent::Locker do
13
@locker = LockerTester.new
14
@locker.stubs(:lockfile_path).returns "/my/lock"
17
it "should use a Pidlock instance as its lockfile" do
18
@locker.lockfile.should be_instance_of(Puppet::Util::Pidlock)
21
it "should use 'lockfile_path' to determine its lockfile path" do
22
@locker.expects(:lockfile_path).returns "/my/lock"
23
lock = Puppet::Util::Pidlock.new("/my/lock")
24
Puppet::Util::Pidlock.expects(:new).with("/my/lock").returns lock
29
it "should reuse the same lock file each time" do
30
@locker.lockfile.should equal(@locker.lockfile)
33
it "should use the lock file to anonymously lock the process when disabled" do
34
@locker.lockfile.expects(:lock).with(:anonymous => true)
39
it "should use the lock file to anonymously unlock the process when enabled" do
40
@locker.lockfile.expects(:unlock).with(:anonymous => true)
45
it "should have a method that yields when a lock is attained" do
46
@locker.lockfile.expects(:lock).returns true
52
yielded.should be_true
55
it "should return true when the lock method successfully locked" do
56
@locker.lockfile.expects(:lock).returns true
58
@locker.lock {}.should be_true
61
it "should return true when the lock method does not receive the lock" do
62
@locker.lockfile.expects(:lock).returns false
64
@locker.lock {}.should be_false
67
it "should not yield when the lock method does not receive the lock" do
68
@locker.lockfile.expects(:lock).returns false
71
@locker.lock { yielded = true }
72
yielded.should be_false
75
it "should not unlock when a lock was not received" do
76
@locker.lockfile.expects(:lock).returns false
77
@locker.lockfile.expects(:unlock).never
82
it "should unlock after yielding upon obtaining a lock" do
83
@locker.lockfile.stubs(:lock).returns true
84
@locker.lockfile.expects(:unlock)
89
it "should unlock after yielding upon obtaining a lock, even if the block throws an exception" do
90
@locker.lockfile.stubs(:lock).returns true
91
@locker.lockfile.expects(:unlock)
93
lambda { @locker.lock { raise "foo" } }.should raise_error(RuntimeError)
96
it "should be considered running if the lockfile is locked" do
97
@locker.lockfile.expects(:locked?).returns true
98
@locker.should be_running