~ubuntu-branches/ubuntu/quantal/puppet/quantal

« back to all changes in this revision

Viewing changes to .pc/puppet-12844/spec/unit/agent/locker_spec.rb

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-07-14 01:56:30 UTC
  • mfrom: (1.1.29) (3.1.43 sid)
  • Revision ID: package-import@ubuntu.com-20120714015630-ntj41rkvkq4zph4y
Tags: 2.7.18-1ubuntu1
* Resynchronise with Debian. (LP: #1023931) Remaining changes:
  - debian/puppetmaster-passenger.postinst: Make sure we error if puppet
    config print doesn't work
  - debian/puppetmaster-passenger.postinst: Ensure upgrades from
    <= 2.7.11-1 fixup passenger apache configuration.
* Dropped upstreamed patches:
  - debian/patches/CVE-2012-1906_CVE-2012-1986_to_CVE-2012-1989.patch
  - debian/patches/puppet-12844
  - debian/patches/2.7.17-Puppet-July-2012-CVE-fixes.patch
* Drop Build-Depends on ruby-rspec (in universe):
  - debian/control: remove ruby-rspec from Build-Depends
  - debian/patches/no-rspec.patch: make Rakefile work anyway if rspec
    isn't installed so we can use it in debian/rules.

Show diffs side-by-side

added added

removed removed

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