From: Jonathan Rockway Date: Mon, 20 Nov 2006 05:17:38 +0000 (+0000) Subject: test for fork also X-Git-Tag: 5.7099_04~256 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=31b71f4bd3cf4137d75cce6e9fe520af752e3c51 test for fork also --- diff --git a/t/lib/TestApp/Controller/Fork.pm b/t/lib/TestApp/Controller/Fork.pm index 0f6e44c..b6992ab 100644 --- a/t/lib/TestApp/Controller/Fork.pm +++ b/t/lib/TestApp/Controller/Fork.pm @@ -9,7 +9,7 @@ use warnings; use base 'Catalyst::Controller'; use YAML; -sub fork : Local { +sub system : Local { my ($self, $c, $ls) = @_; my ($result, $code) = (undef, 1); @@ -40,5 +40,22 @@ sub backticks : Local { $c->response->body(Dump({result => $result, code => $code})); } - + +sub fork : Local { + my ($self, $c) = @_; + my $pid; + my $x = 0; + + if($pid = fork()){ + $x = "ok"; + } + else { + exit(0); + } + + waitpid $pid,0 or die; + + $c->response->body(Dump({pid => $pid, result => $x})); +} + 1; diff --git a/t/live_fork.t b/t/live_fork.t index 148a0d4..5871dcb 100644 --- a/t/live_fork.t +++ b/t/live_fork.t @@ -16,11 +16,11 @@ use lib "$FindBin::Bin/lib"; use Catalyst::Test qw(TestApp); plan 'skip_all' if !-e '/bin/ls'; # see if /bin/ls exists -plan tests => 8; # otherwise +plan tests => 13; # otherwise { - fork: - ok(my $result = get('/fork/fork/%2Fbin%2Fls'), 'get /fork//bin/ls'); + system: + ok(my $result = get('/fork/system/%2Fbin%2Fls'), 'system'); my @result = split /$/m, $result; $result = join q{}, @result[-4..-1]; @@ -32,7 +32,7 @@ plan tests => 8; # otherwise { backticks: - ok(my $result = get('/fork/backticks/%2Fbin%2Fls'), 'get /fork//bin/ls'); + ok(my $result = get('/fork/backticks/%2Fbin%2Fls'), '`backticks`'); my @result = split /$/m, $result; $result = join q{}, @result[-4..-1]; @@ -41,3 +41,15 @@ plan tests => 8; # otherwise is($result_ref->{code}, 0, 'exited successfully'); like($result_ref->{result}, qr{^/bin/ls[^:]}, 'contains ^/bin/ls$'); } +{ + fork: + ok(my $result = get('/fork/fork'), 'fork'); + my @result = split /$/m, $result; + $result = join q{}, @result[-4..-1]; + + my $result_ref = eval { Load($result) }; + ok($result_ref, 'is YAML'); + isnt($result_ref->{pid}, 0, q{fork's "pid" wasn't 0}); + isnt($result_ref->{pid}, $$, 'fork got a new pid'); + is($result_ref->{result}, 'ok', 'fork was effective'); +}