Commit | Line | Data |
3543c999 |
1 | use Test::More tests => 4; |
7d7115e5 |
2 | use Test::MooseX::Daemonize; |
3543c999 |
3 | use MooseX::Daemonize; |
a4952679 |
4 | |
5 | ## Since a daemon will not be able to print terminal output, we |
6 | ## have a test daemon create a file, and another process test for |
7 | ## its existence. |
8 | |
9 | { |
10 | |
11 | package FileMaker; |
12 | use Moose; |
13 | with qw(MooseX::Daemonize); |
14 | |
7d7115e5 |
15 | has filename => ( isa => 'Str', is => 'ro' ); |
2eced271 |
16 | |
7d7115e5 |
17 | after start => sub { $_[0]->create_file( $_[0]->filename ) }; |
18 | |
a4952679 |
19 | sub create_file { |
20 | my ( $self, $file ) = @_; |
3543c999 |
21 | open( my $FILE, ">$file" ) || die $!; |
22 | close($FILE); |
a4952679 |
23 | } |
24 | |
25 | no Moose; |
26 | } |
27 | |
28 | package main; |
b916501e |
29 | use strict; |
30 | use warnings; |
7d7115e5 |
31 | use Cwd; |
a4952679 |
32 | |
33 | ## Try to make sure we are in the test directory |
7d7115e5 |
34 | chdir 't' if ( Cwd::cwd() !~ m|/t$| ); |
a4952679 |
35 | my $cwd = Cwd::cwd(); |
a4952679 |
36 | |
3543c999 |
37 | my $app = FileMaker->new( |
38 | pidbase => $cwd, |
39 | filename => "$cwd/im_alive", |
40 | ); |
41 | daemonize_ok( $app, 'child forked okay' ); |
b916501e |
42 | ok( -e $app->filename, "file exists" ); |
3543c999 |
43 | ok( $app->stop( no_exit => 1 ), 'app stopped' ); |
b916501e |
44 | ok( not(-e $app->pidfile) , 'pidfile gone' ); |
3543c999 |
45 | unlink( $app->filename ); |