summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMatt Robinson <matt@puppetlabs.com>2012-01-03 10:44:12 -0800
committerMatt Robinson <matt@puppetlabs.com>2012-01-03 10:44:12 -0800
commit5d3369ebb4f1af53a9a6395317f1f8af8b589630 (patch)
tree07eceb6ea5f53d932c6aec94112107adcc1dcec8 /test
parent3a1fe3720788e6b616ed29902b9f281a5073b65c (diff)
parentac8b408e18390ebf1bc31a3bab7df9d269b2629e (diff)
downloadpuppet-5d3369ebb4f1af53a9a6395317f1f8af8b589630.tar.gz
Merge branch '2.7.x'
* 2.7.x: (21 commits) (#7296) Make the Debian service provider handle services that don't conform to the debain policy manual. (#4836) - Agent --disable should allow to put a message (#3757) - Refactor enable/disable to its own module (#3757) - Move enable/disable to its own lock Fix failing tests with ruby 1.9.2 in the instrumentation framework Use all lower-case file name for Puppet::Util::Instrumentation::Instrumentable Maint: Fix typo in usage example for create_resources function Set of faces to manage instrumentation listeners, data and probes Example probes for the indirector Add probe indirection for probe management Process name instrumentation listener Add the 'performance' instrumentation listener Add the example 'log' listener Add a way to add probe to puppet code Add indirection (REST usable) to manipulate instrumentation Instrumentation foundation layer (#8119) Write reports to a temporary file and move them into place (#11414) Test Augeas versions correctly with versioncmp (#11414) Save/execute changes on versions of Augeas < 0.3.6 Updated CHANGELOG for 2.6.13 ... Conflicts: spec/unit/application/agent_spec.rb spec/unit/provider/augeas/augeas_spec.rb
Diffstat (limited to 'test')
-rwxr-xr-xtest/util/pidlock.rb126
1 files changed, 0 insertions, 126 deletions
diff --git a/test/util/pidlock.rb b/test/util/pidlock.rb
deleted file mode 100755
index beaff1089..000000000
--- a/test/util/pidlock.rb
+++ /dev/null
@@ -1,126 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/../lib/puppettest')
-
-require 'puppet/util/pidlock'
-require 'fileutils'
-
-# This is *fucked* *up*
-Puppet.debug = false
-
-class TestPuppetUtilPidlock < Test::Unit::TestCase
- include PuppetTest
-
- def setup
- super
- @workdir = tstdir
- end
-
- def teardown
- super
- FileUtils.rm_rf(@workdir)
- end
-
- def test_00_basic_create
- l = nil
- assert_nothing_raised { l = Puppet::Util::Pidlock.new(@workdir + '/nothingmuch') }
-
- assert_equal Puppet::Util::Pidlock, l.class
-
- assert_equal @workdir + '/nothingmuch', l.lockfile
- end
-
- def test_10_uncontended_lock
- l = Puppet::Util::Pidlock.new(@workdir + '/test_lock')
-
- assert !l.locked?
- assert !l.mine?
- assert l.lock
- assert l.locked?
- assert l.mine?
- assert !l.anonymous?
- # It's OK to call lock multiple times
- assert l.lock
- assert l.unlock
- assert !l.locked?
- assert !l.mine?
- end
-
- def test_20_someone_elses_lock
- childpid = nil
- l = Puppet::Util::Pidlock.new(@workdir + '/someone_elses_lock')
-
- # First, we need a PID that's guaranteed to be (a) used, (b) someone
- # else's, and (c) around for the life of this test.
- childpid = fork { loop do; sleep 10; end }
-
- File.open(l.lockfile, 'w') { |fd| fd.write(childpid) }
-
- assert l.locked?
- assert !l.mine?
- assert !l.lock
- assert l.locked?
- assert !l.mine?
- assert !l.unlock
- assert l.locked?
- assert !l.mine?
- ensure
- Process.kill("KILL", childpid) unless childpid.nil?
- end
-
- def test_30_stale_lock
- # This is a bit hard to guarantee, but we need a PID that is definitely
- # unused, and will stay so for the the life of this test. Our best
- # bet is to create a process, get it's PID, let it die, and *then*
- # lock on it.
- childpid = fork { exit }
-
- # Now we can't continue until we're sure that the PID is dead
- Process.wait(childpid)
-
- l = Puppet::Util::Pidlock.new(@workdir + '/stale_lock')
-
- # locked? should clear the lockfile
- File.open(l.lockfile, 'w') { |fd| fd.write(childpid) }
- assert File.exists?(l.lockfile)
- assert !l.locked?
- assert !File.exists?(l.lockfile)
-
- # lock should replace the lockfile with our own
- File.open(l.lockfile, 'w') { |fd| fd.write(childpid) }
- assert File.exists?(l.lockfile)
- assert l.lock
- assert l.locked?
- assert l.mine?
-
- # unlock should fail, and should *not* molest the existing lockfile,
- # despite it being stale
- File.open(l.lockfile, 'w') { |fd| fd.write(childpid) }
- assert File.exists?(l.lockfile)
- assert !l.unlock
- assert File.exists?(l.lockfile)
- end
-
- def test_40_not_locked_at_all
- l = Puppet::Util::Pidlock.new(@workdir + '/not_locked')
-
- assert !l.locked?
- # We can't unlock if we don't hold the lock
- assert !l.unlock
- end
-
- def test_50_anonymous_lock
- l = Puppet::Util::Pidlock.new(@workdir + '/anonymous_lock')
-
- assert !l.locked?
- assert l.lock(:anonymous => true)
- assert l.locked?
- assert l.anonymous?
- assert !l.mine?
- assert "", File.read(l.lockfile)
- assert !l.unlock
- assert l.locked?
- assert l.anonymous?
- assert l.unlock(:anonymous => true)
- assert !File.exists?(l.lockfile)
- end
-end
-