Sha256: 1262d6f335299732243c41683f61cc90c2220d828addd1fbc45e16302d94b23b

Contents?: true

Size: 1.67 KB

Versions: 10

Compression:

Stored size: 1.67 KB

Contents

#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/../lib/puppettest'

require 'puppettest'
require 'puppet/daemon'

class TestDaemon < Test::Unit::TestCase
	include PuppetTest

    class FakeDaemon
        include Puppet::Daemon
    end

    def test_pidfile
        daemon = FakeDaemon.new

        assert_nothing_raised("removing non-existent file failed") do
            daemon.rmpidfile
        end

        Puppet[:pidfile] = tempfile()
        assert_nothing_raised "could not lock" do
            daemon.setpidfile
        end

        assert(FileTest.exists?(daemon.pidfile),
            "did not create pidfile")

        assert_nothing_raised("removing non-existent file failed") do
            daemon.rmpidfile
        end

        assert(! FileTest.exists?(daemon.pidfile),
            "did not remove pidfile")
    end

    def test_daemonize
        daemon = FakeDaemon.new
        Puppet[:pidfile] = tempfile()

        exiter = tempfile()

        assert_nothing_raised("Could not fork and daemonize") do
            fork do
                daemon.send(:daemonize)
                # Wait a max of 5 secs
                50.times do
                    if FileTest.exists?(exiter)
                        daemon.rmpidfile
                        exit(0)
                    end
                    sleep 0.1
                end
                exit(0)
            end
        end
        sleep(0.1)
        assert(FileTest.exists?(Puppet[:pidfile]),
            "did not create pidfile on daemonize")

        File.open(exiter, "w") { |f| f.puts "" }

        sleep(0.2)
        assert(! FileTest.exists?(Puppet[:pidfile]),
            "did not remove pidfile on process death")
    end
end


Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
puppet-0.24.9 test/network/daemon.rb
puppet-0.24.0 test/network/daemon.rb
puppet-0.24.3 test/network/daemon.rb
puppet-0.24.4 test/network/daemon.rb
puppet-0.24.1 test/network/daemon.rb
puppet-0.24.2 test/network/daemon.rb
puppet-0.24.5 test/network/daemon.rb
puppet-0.24.6 test/network/daemon.rb
puppet-0.24.7 test/network/daemon.rb
puppet-0.24.8 test/network/daemon.rb