App-Base

 view release on metacpan or  search on metacpan

t/daemon.t  view on Meta::CPAN

    return 'This is a test daemon.';
}

sub handle_shutdown {
    return;
}

no Moose;
__PACKAGE__->meta->make_immutable;

package Test::Daemon::Suicidal;
use Time::HiRes;
use POSIX qw(SIGTERM);

use Moose;
with 'App::Base::Daemon';

sub daemon_run {

    # This will never actually loop, but I want to guarantee that the
    # daemon does not exit by reaching return()

t/daemon.t  view on Meta::CPAN

}

NO_FORK:
{
    local @ARGV = ('--no-fork', '--no-pid-file');
    is(0, Test::Daemon::Exiting->new->run, '--no-fork runs and returns 0');
}

LE_ROI_SE_MEURT:
{
    my $pidfile = $pdir->child('Test::Daemon::Suicidal.pid');
    local $ENV{APP_BASE_DAEMON_PIDDIR} = $pdir;
    is(Test::Daemon::Suicidal->new->run, 0, 'Test::Suicidal daemon spawns detached child process');
    wait_file($pidfile);
    ok(-f $pidfile, "Suicidal pid file exists");
    chomp(my $pid = read_file($pidfile));
    my $count = 50;
    while (kill(ZERO => $pid) and $count--) {
        Time::HiRes::usleep(50_000);
    }
    ok(!kill(ZERO => $pid), "Suicidal grandchild process has gone");
}

if ($> == 0) {
    local $ENV{APP_BASE_DAEMON_PIDDIR} = $pdir;
    unlink $pidfile;
    is(
        Test::Daemon->new({
                user  => 'nobody',
                group => 'nogroup',
            },



( run in 0.611 second using v1.01-cache-2.11-cpan-de7293f3b23 )