The nginx bullshit can just die
[catagits/Catalyst-Runtime.git] / t / live_fork.t
1 #!/usr/bin/perl
2 # live_fork.t
3 # Copyright (c) 2006 Jonathan Rockway <jrockway@cpan.org>
4
5 =head1 SYNOPSIS
6
7 Tests if Catalyst can fork/exec other processes successfully
8
9 =cut
10 use strict;
11 use warnings;
12 use Test::More;
13 use FindBin;
14 use lib "$FindBin::Bin/lib";
15 use Catalyst::Test qw(TestApp);
16
17 eval 'use YAML';
18 plan skip_all => 'YAML required' if $@;
19
20 plan skip_all => 'Using remote server (and REMOTE_FORK not set)'
21     if $ENV{CATALYST_SERVER} && !$ENV{REMOTE_FORK};
22
23 plan skip_all => 'Skipping fork tests: no /bin/ls'
24     if !-e '/bin/ls'; # see if /bin/ls exists
25
26 plan tests => 13; # otherwise
27
28 {
29     ok(my $result = get('/fork/system/%2Fbin%2Fls'), 'system');
30     my @result = split /$/m, $result;
31     $result = join q{}, @result[-4..-1];
32
33     my $result_ref = eval { Load($result) };
34     ok($result_ref, 'is YAML');
35     is($result_ref->{result}, 0, 'exited OK');
36 }
37
38 {
39     ok(my $result = get('/fork/backticks/%2Fbin%2Fls'), '`backticks`');
40     my @result = split /$/m, $result;
41     $result = join q{}, @result[-4..-1];
42
43     my $result_ref = eval { Load($result) };
44     ok($result_ref, 'is YAML');
45     is($result_ref->{code}, 0, 'exited successfully');
46     like($result_ref->{result}, qr{^/bin/ls[^:]}, 'contains ^/bin/ls$');
47     like($result_ref->{result}, qr{\n.*\n}m, 'contains two newlines');
48 }
49 {
50     ok(my $result = get('/fork/fork'), 'fork');
51     my @result = split /$/m, $result;
52     $result = join q{}, @result[-4..-1];
53
54     my $result_ref = eval { Load($result) };
55     ok($result_ref, 'is YAML');
56     isnt($result_ref->{pid}, 0, q{fork's "pid" wasn't 0});
57     isnt($result_ref->{pid}, $$, 'fork got a new pid');
58     is($result_ref->{result}, 'ok', 'fork was effective');
59 }