Commit | Line | Data |
a4952679 |
1 | use Test::More no_plan => 1; |
2 | use Proc::Daemon; |
3 | use Cwd; |
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 | |
15 | sub create_file { |
16 | my ( $self, $file ) = @_; |
17 | open( FILE, ">$file" ) || die $!; |
18 | close(FILE); |
19 | } |
20 | |
21 | no Moose; |
22 | } |
23 | |
24 | package main; |
25 | |
26 | ## Try to make sure we are in the test directory |
27 | my $cwd = Cwd::cwd(); |
28 | chdir 't' if ( $cwd !~ m|/t$| ); |
29 | $cwd = Cwd::cwd(); |
30 | |
31 | ## Test filename |
32 | my $file = join( '/', $cwd, 'im_alive' ); |
33 | ## Parent process will check if file created. Child becomes the daemon. |
34 | if ( my $pid = Proc::Daemon::Fork ) { |
35 | sleep(5); # Punt on sleep time, 5 seconds should be enough |
36 | ok( -e $file, "$file exists"); |
37 | unlink($file); |
38 | } |
39 | else { |
40 | my $daemon = FileMaker->new(pidbase => '.'); |
41 | $daemon->start(); |
42 | $daemon->create_file($file); |
43 | $daemon->stop(); |
44 | exit; |
45 | } |