4 use Test::More tests => 25;
8 use_ok('MooseX::Daemonize::Pid::File');
12 my $f = MooseX::Daemonize::Pid::File->new(
13 file => [ 't', 'foo.pid' ]
15 isa_ok($f, 'MooseX::Daemonize::Pid::File');
17 isa_ok($f->file, 'Path::Class::File');
19 is($f->pid, $$, '... the PID is our current process');
22 exception { $f->write },
24 '... writing the PID file',
27 is($f->file->slurp(chomp => 1), $f->pid, '... the PID in the file is correct');
29 ok($f->is_running, '... it is running too');
32 exception { $f->remove },
34 '... removing the PID file',
37 ok(!-e $f->file, '... the PID file does not exist anymore');
41 my $f = MooseX::Daemonize::Pid::File->new(
42 file => [ 't', 'bar.pid' ]
44 isa_ok($f, 'MooseX::Daemonize::Pid::File');
46 isa_ok($f->file, 'Path::Class::File');
49 exception { $f->write },
51 '... writing the PID file',
54 is($f->file->slurp(chomp => 1), $f->pid, '... the PID in the file is correct');
55 is($f->pid, $$, '... the PID is our current process');
57 ok($f->is_running, '... it is running too');
60 exception { $f->remove },
62 '... removing the PID file',
65 ok(!-e $f->file, '... the PID file does not exist anymore');
69 # find a pid that doesn't currently exist - start by looking at our own
70 # and going backwards (not 100% reliable but better than hardcoding one)
72 do { $PID--; $PID = 2**32 if $PID < 1 } while kill(0, $PID);
73 diag 'assigning the non-existent pid ' . $PID;
75 my $f = MooseX::Daemonize::Pid::File->new(
76 file => [ 't', 'baz.pid' ],
79 isa_ok($f, 'MooseX::Daemonize::Pid::File');
81 isa_ok($f->file, 'Path::Class::File');
83 is($f->pid, $PID, '... the PID is our made up PID');
86 exception { $f->write },
88 '... writing the PID file',
91 is($f->file->slurp(chomp => 1), $f->pid, '... the PID in the file is correct');
93 ok(!$f->is_running, '... it is not running (cause we made the PID up)');
96 exception { $f->remove },
98 '... removing the PID file',
101 ok(!-e $f->file, '... the PID file does not exist anymore');