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