6 use File::Spec::Functions;
8 use Test::More tests => 29;
12 use_ok('MooseX::Daemonize');
15 use constant DEBUG => 0;
18 my $FILENAME = "$CWD/im_alive";
19 $ENV{MX_DAEMON_STDOUT} = catfile($CWD, 'Out.txt');
20 $ENV{MX_DAEMON_STDERR} = catfile($CWD, 'Err.txt');
26 with qw(MooseX::Daemonize);
28 has filename => ( isa => 'Str', is => 'ro' );
32 if ($self->is_daemon) {
33 $self->create_file( $self->filename );
38 my ( $self, $file ) = @_;
39 open( my $FILE, ">$file" ) || die $!;
44 my $app = FileMaker->new(
46 filename => $FILENAME,
48 isa_ok($app, 'FileMaker');
49 does_ok($app, 'MooseX::Daemonize');
50 does_ok($app, 'MooseX::Daemonize::WithPidFile');
51 does_ok($app, 'MooseX::Daemonize::Core');
53 isa_ok($app->pidfile, 'MooseX::Daemonize::Pid::File');
55 is($app->pidfile->file, "$CWD/filemaker.pid", '... got the right PID file path');
56 ok(not(-e $app->pidfile->file), '... our pidfile does not exist');
58 ok(!$app->status, '... the daemon is running');
59 is($app->exit_code, MooseX::Daemonize->ERROR, '... got the right error code');
61 ok($app->stop, '... the app will stop cause its not running');
62 is($app->status_message, "Not running", '... got the correct status message');
63 is($app->exit_code, MooseX::Daemonize->OK, '... got the right error code');
67 ok($app->start, '... daemon started');
68 is($app->status_message, "Start succeeded", '... got the correct status message');
69 is($app->exit_code, MooseX::Daemonize->OK, '... got the right error code');
71 sleep(1); # give it a second ...
73 ok(-e $app->pidfile->file, '... our pidfile exists' );
75 my $pid = $app->pidfile->pid;
76 isnt($pid, $$, '... the pid in our pidfile is correct (and not us)');
78 ok($app->status, '... the daemon is running');
79 is($app->status_message, "Daemon is running with pid ($pid)", '... got the correct status message');
80 is($app->exit_code, MooseX::Daemonize->OK, '... got the right error code');
84 diag "Status is: " . $app->status_message;
87 ok( -e $app->filename, "file exists" );
91 diag "Status is: " . $app->status_message;
94 ok( $app->stop, '... app stopped' );
95 is($app->status_message, "Stop succeeded", '... got the correct status message');
96 is($app->exit_code, MooseX::Daemonize->OK, '... got the right error code');
98 ok(!$app->status, '... the daemon is no longer running');
99 is($app->status_message, "Daemon is not running with pid ($pid)", '... got the correct status message');
100 is($app->exit_code, MooseX::Daemonize->ERROR, '... got the right error code');
104 diag "Status is: " . $app->status_message;
107 ok( not(-e $app->pidfile->file) , '... pidfile gone' );
110 unlink $ENV{MX_DAEMON_STDOUT};
111 unlink $ENV{MX_DAEMON_STDERR};