Commit | Line | Data |
2eced271 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More tests => 25; |
7 | use Test::Exception; |
8 | |
9 | BEGIN { |
d8985b7d |
10 | use_ok('MooseX::Daemonize::Pid::File'); |
2eced271 |
11 | } |
12 | |
13 | { |
d8985b7d |
14 | my $f = MooseX::Daemonize::Pid::File->new( |
2eced271 |
15 | file => [ 't', 'foo.pid' ] |
16 | ); |
d8985b7d |
17 | isa_ok($f, 'MooseX::Daemonize::Pid::File'); |
2eced271 |
18 | |
19 | isa_ok($f->file, 'Path::Class::File'); |
20 | |
21 | is($f->pid, $$, '... the PID is our current process'); |
22 | |
23 | lives_ok { |
24 | $f->write |
25 | } '... writing the PID file'; |
26 | |
27 | is($f->file->slurp(chomp => 1), $f->pid, '... the PID in the file is correct'); |
28 | |
d8985b7d |
29 | ok($f->is_running, '... it is running too'); |
2eced271 |
30 | |
31 | lives_ok { |
32 | $f->remove |
33 | } '... removing the PID file'; |
34 | |
35 | ok(!-e $f->file, '... the PID file does not exist anymore'); |
36 | } |
37 | |
38 | { |
d8985b7d |
39 | my $f = MooseX::Daemonize::Pid::File->new( |
2eced271 |
40 | file => [ 't', 'bar.pid' ] |
41 | ); |
d8985b7d |
42 | isa_ok($f, 'MooseX::Daemonize::Pid::File'); |
2eced271 |
43 | |
44 | isa_ok($f->file, 'Path::Class::File'); |
45 | |
46 | lives_ok { |
47 | $f->write |
48 | } '... writing the PID file'; |
49 | |
50 | is($f->file->slurp(chomp => 1), $f->pid, '... the PID in the file is correct'); |
51 | is($f->pid, $$, '... the PID is our current process'); |
52 | |
d8985b7d |
53 | ok($f->is_running, '... it is running too'); |
2eced271 |
54 | |
55 | lives_ok { |
56 | $f->remove |
57 | } '... removing the PID file'; |
58 | |
59 | ok(!-e $f->file, '... the PID file does not exist anymore'); |
60 | } |
61 | |
62 | { |
8ac4733f |
63 | my $PID = 9999; |
2eced271 |
64 | |
d8985b7d |
65 | my $f = MooseX::Daemonize::Pid::File->new( |
2eced271 |
66 | file => [ 't', 'baz.pid' ], |
67 | pid => $PID, |
68 | ); |
d8985b7d |
69 | isa_ok($f, 'MooseX::Daemonize::Pid::File'); |
2eced271 |
70 | |
71 | isa_ok($f->file, 'Path::Class::File'); |
72 | |
73 | is($f->pid, $PID, '... the PID is our made up PID'); |
74 | |
75 | lives_ok { |
76 | $f->write |
77 | } '... writing the PID file'; |
78 | |
79 | is($f->file->slurp(chomp => 1), $f->pid, '... the PID in the file is correct'); |
80 | |
d8985b7d |
81 | ok(!$f->is_running, '... it is not running (cause we made the PID up)'); |
2eced271 |
82 | |
83 | lives_ok { |
84 | $f->remove |
85 | } '... removing the PID file'; |
86 | |
87 | ok(!-e $f->file, '... the PID file does not exist anymore'); |
88 | } |