6 use File::Spec::Functions;
12 use File::Temp qw(tempdir);
14 my $dir = tempdir( CLEANUP => 1 );
17 eval 'use POE::Kernel;';
18 plan skip_all => "POE required for this test" if $@;
20 use_ok('MooseX::Daemonize::Core');
24 use constant DEBUG => 0;
26 my $PIDFILE = catfile($dir, 'test-app.pid');
27 $ENV{MX_DAEMON_STDOUT} = catfile($dir, 'Out.txt');
28 $ENV{MX_DAEMON_STDERR} = catfile($dir, 'Err.txt');
30 unlink $PIDFILE; # clean up anythinf leftover by last run
37 with 'MooseX::Daemonize::WithPidFile';
40 MooseX::Daemonize::Pid::File->new( file => $PIDFILE )
46 # this tests our bad PID
47 # cleanup functionality.
48 print "Our parent PID is " . $self->pidfile->pid . "\n" if ::DEBUG;
51 return unless $self->is_daemon;
53 my $session = POE::Session->create(
56 my ($kernel, $heap) = @_[KERNEL, HEAP];
58 print "Hello from $$\n";
60 $heap->[0] = $kernel->delay_set('say_hello', 10);
63 my ($kernel, $heap) = @_[KERNEL, HEAP];
64 $kernel->sig( INT => 'terminate');
66 $kernel->yield('say_hello');
69 my ($kernel, $heap) = @_[KERNEL, HEAP];
70 $self->pidfile->remove if $self->pidfile->pid == $$;
77 # make it easy to find with ps
84 my $d = MyFooDaemon->new( pidfile => $PIDFILE );
85 isa_ok($d, 'MyFooDaemon');
86 does_ok($d, 'MooseX::Daemonize::Core');
87 does_ok($d, 'MooseX::Daemonize::WithPidFile');
89 ok($d->has_pidfile, '... we have a pidfile value');
93 isa_ok($p, 'MooseX::Daemonize::Pid::File');
97 ok(!(-e $PIDFILE), '... the PID file does not exist yet');
101 } '... successfully daemonized from (' . $$ . ')';
104 isa_ok($p, 'MooseX::Daemonize::Pid::File');
109 ok($p->does_file_exist, '... the PID file exists');
110 ok($p->is_running, '... the daemon process is running (' . $p->pid . ')');
116 diag `ps -x | grep test-app`;
121 diag "killed $pid" if DEBUG;
126 diag `ps -x | grep test-app`;
129 ok(!$p->is_running, '... the daemon process is no longer running (' . $p->pid . ')');
130 ok(!(-e $PIDFILE), '... the PID file has been removed');
132 unlink $ENV{MX_DAEMON_STDOUT};
133 unlink $ENV{MX_DAEMON_STDERR};