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