~nvalcarcel/ubuntu/lucid/puppet/fix-546677

« back to all changes in this revision

Viewing changes to spec/unit/agent/locker.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env ruby
 
2
 
 
3
require File.dirname(__FILE__) + '/../../spec_helper'
 
4
require 'puppet/agent'
 
5
require 'puppet/agent/locker'
 
6
 
 
7
class LockerTester
 
8
    include Puppet::Agent::Locker
 
9
end
 
10
 
 
11
describe Puppet::Agent::Locker do
 
12
    before do
 
13
        @locker = LockerTester.new
 
14
        @locker.stubs(:lockfile_path).returns "/my/lock"
 
15
    end
 
16
 
 
17
    it "should use a Pidlock instance as its lockfile" do
 
18
        @locker.lockfile.should be_instance_of(Puppet::Util::Pidlock)
 
19
    end
 
20
 
 
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
 
25
 
 
26
        @locker.lockfile
 
27
    end
 
28
 
 
29
    it "should reuse the same lock file each time" do
 
30
        @locker.lockfile.should equal(@locker.lockfile)
 
31
    end
 
32
 
 
33
    it "should use the lock file to anonymously lock the process when disabled" do
 
34
        @locker.lockfile.expects(:lock).with(:anonymous => true)
 
35
 
 
36
        @locker.disable
 
37
    end
 
38
 
 
39
    it "should use the lock file to anonymously unlock the process when enabled" do
 
40
        @locker.lockfile.expects(:unlock).with(:anonymous => true)
 
41
 
 
42
        @locker.enable
 
43
    end
 
44
 
 
45
    it "should have a method that yields when a lock is attained" do
 
46
        @locker.lockfile.expects(:lock).returns true
 
47
 
 
48
        yielded = false
 
49
        @locker.lock do
 
50
            yielded = true
 
51
        end
 
52
        yielded.should be_true
 
53
    end
 
54
 
 
55
    it "should return true when the lock method successfully locked" do
 
56
        @locker.lockfile.expects(:lock).returns true
 
57
 
 
58
        @locker.lock {}.should be_true
 
59
    end
 
60
 
 
61
    it "should return true when the lock method does not receive the lock" do
 
62
        @locker.lockfile.expects(:lock).returns false
 
63
 
 
64
        @locker.lock {}.should be_false
 
65
    end
 
66
 
 
67
    it "should not yield when the lock method does not receive the lock" do
 
68
        @locker.lockfile.expects(:lock).returns false
 
69
 
 
70
        yielded = false
 
71
        @locker.lock { yielded = true }
 
72
        yielded.should be_false
 
73
    end
 
74
 
 
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
 
78
 
 
79
        @locker.lock {}
 
80
    end
 
81
 
 
82
    it "should unlock after yielding upon obtaining a lock" do
 
83
        @locker.lockfile.stubs(:lock).returns true
 
84
        @locker.lockfile.expects(:unlock)
 
85
 
 
86
        @locker.lock {}
 
87
    end
 
88
 
 
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)
 
92
 
 
93
        lambda { @locker.lock { raise "foo" } }.should raise_error(RuntimeError)
 
94
    end
 
95
 
 
96
    it "should be considered running if the lockfile is locked" do
 
97
        @locker.lockfile.expects(:locked?).returns true
 
98
        @locker.should be_running
 
99
    end
 
100
end