6 use File::Spec::Functions;
8 use Test::More no_plan => 1;
11 use File::Temp qw(tempdir);
13 my $dir = tempdir( CLEANUP => 1 );
17 use_ok('MooseX::Daemonize::Core');
20 use constant DEBUG => 0;
22 my $PIDFILE = catfile($dir, 'test-app.pid');
23 $ENV{MX_DAEMON_STDOUT} = catfile($dir, 'Out.txt');
24 $ENV{MX_DAEMON_STDERR} = catfile($dir, 'Err.txt');
30 with 'MooseX::Daemonize::WithPidFile';
33 MooseX::Daemonize::Pid::File->new( file => $PIDFILE )
39 # this tests our bad PID
40 # cleanup functionality.
41 print "Our parent PID is " . $self->pidfile->pid . "\n" if ::DEBUG;
44 return unless $self->is_daemon;
46 # make it easy to find with ps
49 print "Got INT! Oh Noes!";
50 $self->pidfile->remove;
54 print "Hello from $$\n";
61 my $d = MyFooDaemon->new( pidfile => $PIDFILE );
62 isa_ok($d, 'MyFooDaemon');
63 does_ok($d, 'MooseX::Daemonize::Core');
64 does_ok($d, 'MooseX::Daemonize::WithPidFile');
66 ok($d->has_pidfile, '... we have a pidfile value');
70 isa_ok($p, 'MooseX::Daemonize::Pid::File');
74 ok(!(-e $PIDFILE), '... the PID file does not exist yet');
78 } '... successfully daemonized from (' . $$ . ')';
81 isa_ok($p, 'MooseX::Daemonize::Pid::File');
86 ok($p->does_file_exist, '... the PID file exists');
87 ok($p->is_running, '... the daemon process is running (' . $p->pid . ')');
93 diag `ps -x | grep test-app`;
98 diag "killed $pid" if DEBUG;
103 diag `ps -x | grep test-app`;
106 ok(!$p->is_running, '... the daemon process is no longer running (' . $p->pid . ')');
107 ok(!(-e $PIDFILE), '... the PID file has been removed');
109 unlink $ENV{MX_DAEMON_STDOUT};
110 unlink $ENV{MX_DAEMON_STDERR};