This is an automated email from the git hooks/post-receive script. js pushed a commit to branch master in repository libplack-test-anyevent-perl.
commit 2c21c03de8a38b20c2588e81d9deda62bc147e67 Author: Daisuke (yet another) Maki <maki.dais...@gmail.com> Date: Mon Jan 26 21:09:57 2015 +0900 Fixed issue #5 Fixed "$res->recv dies when PSGI app passes 3-length array to responder". --- lib/Plack/Test/AnyEvent.pm | 4 ++- lib/Plack/Test/AnyEvent/Response.pm | 1 + t/05-three-length-array-to-responder.t | 52 ++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/lib/Plack/Test/AnyEvent.pm b/lib/Plack/Test/AnyEvent.pm index a6bbd05..aa57bdc 100644 --- a/lib/Plack/Test/AnyEvent.pm +++ b/lib/Plack/Test/AnyEvent.pm @@ -59,16 +59,18 @@ sub test_psgi { if(defined $body) { $res = Plack::Test::AnyEvent::Response->from_psgi([ $status, $headers, $body ]); + $res->{'_cond'} = AnyEvent->condvar; + $res->{'_cond'}->send; } else { push @$headers, 'Transfer-Encoding', 'chunked'; $res = Plack::Test::AnyEvent::Response->from_psgi([ $status, $headers, [] ]); - $res->on_content_received(sub {}); my $h; $res->{'_cond'} = AnyEvent->condvar(cb => sub { undef $h; close $read; close $write; }); + $res->on_content_received(sub {}); $h = AnyEvent::Handle->new( fh => $read, diff --git a/lib/Plack/Test/AnyEvent/Response.pm b/lib/Plack/Test/AnyEvent/Response.pm index 1cc7c94..b75e8f2 100644 --- a/lib/Plack/Test/AnyEvent/Response.pm +++ b/lib/Plack/Test/AnyEvent/Response.pm @@ -38,6 +38,7 @@ sub on_content_received { if($cb) { $self->{'_on_content_received'} = $cb; + $cb->($self->content) if $self->{_cond}->ready; } return $self->{'_on_content_received'}; } diff --git a/t/05-three-length-array-to-responder.t b/t/05-three-length-array-to-responder.t new file mode 100644 index 0000000..2b58e43 --- /dev/null +++ b/t/05-three-length-array-to-responder.t @@ -0,0 +1,52 @@ +#!/usr/bin/env perl + +use strict; +use Test::More tests => 5; + +use Plack::Test; +$Plack::Test::Impl = 'AnyEvent'; + +use AnyEvent; +use HTTP::Request::Common; + + +my $app = sub { + my ( $env ) = @_; + + sub{ + my $responder = shift; + if($env->{QUERY_STRING} =~ /3-length/) { + $responder->([200, ['Content-Type' => 'text/plain'], ['ok']]); + } else { + my $writer = $responder->([200, ['Content-Type' => 'text/plain']]); + $writer->write('ok'); + $writer->close(); + } + } +}; + +test_psgi $app, sub{ + my ( $cb ) = @_; + + my $num_callbacks_invoked = 0; + + my $res = $cb->(GET '/'); + $res->on_content_received(sub { + $num_callbacks_invoked++; + is $res->code, 200; + is $res->content, 'ok'; + }); + $res->recv; + + my $res = $cb->(GET '/?3-length'); + $res->on_content_received(sub{ + $num_callbacks_invoked++; + is $res->code, 200; + is $res->content, 'ok'; + }); + $res->recv; + + is $num_callbacks_invoked, 2, 'make sure that both callbacks have been invoked'; +}; + +done_testing; -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libplack-test-anyevent-perl.git _______________________________________________ Pkg-perl-cvs-commits mailing list Pkg-perl-cvs-commits@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits