7 use File::Spec::Functions;
14 eval 'use POE::Kernel;';
15 plan skip_all => "POE required for this test" if $@;
17 use_ok('MooseX::Daemonize::Core');
21 use constant DEBUG => 0;
24 my $PIDFILE = catfile($CWD, 'test-app.pid');
25 $ENV{MX_DAEMON_STDOUT} = catfile($CWD, 'Out.txt');
26 $ENV{MX_DAEMON_STDERR} = catfile($CWD, 'Err.txt');
33 with 'MooseX::Daemonize::WithPidFile';
36 MooseX::Daemonize::Pid::File->new( file => $PIDFILE )
42 # this tests our bad PID
43 # cleanup functionality.
44 print "Our parent PID is " . $self->pidfile->pid . "\n" if ::DEBUG;
47 return unless $self->is_daemon;
49 my $session = POE::Session->create(
52 my ($kernel, $heap) = @_[KERNEL, HEAP];
54 print "Hello from $$\n";
56 $heap->[0] = $kernel->delay_set('say_hello', 10);
59 my ($kernel, $heap) = @_[KERNEL, HEAP];
60 $kernel->sig( INT => 'terminate');
62 $kernel->yield('say_hello');
65 my ($kernel, $heap) = @_[KERNEL, HEAP];
72 # make it easy to find with ps
79 my $d = MyFooDaemon->new( pidfile => $PIDFILE );
80 isa_ok($d, 'MyFooDaemon');
81 does_ok($d, 'MooseX::Daemonize::Core');
82 does_ok($d, 'MooseX::Daemonize::WithPidFile');
84 ok($d->has_pidfile, '... we have a pidfile value');
88 isa_ok($p, 'MooseX::Daemonize::Pid::File');
92 ok(!(-e $PIDFILE), '... the PID file does not exist yet');
96 } '... successfully daemonized from (' . $$ . ')';
99 isa_ok($p, 'MooseX::Daemonize::Pid::File');
104 ok($p->does_file_exist, '... the PID file exists');
105 ok($p->is_running, '... the daemon process is running (' . $p->pid . ')');
111 diag `ps -x | grep test-app`;
116 diag "killed $pid" if DEBUG;
121 diag `ps -x | grep test-app`;
124 ok(!$p->is_running, '... the daemon process is no longer running (' . $p->pid . ')');
125 ok(!(-e $PIDFILE), '... the PID file has been removed');
127 unlink $ENV{MX_DAEMON_STDOUT};
128 unlink $ENV{MX_DAEMON_STDERR};