1#!perl 2 3BEGIN { 4 unless ($ENV{AUTHOR_TESTING}) { 5 require Test::More; 6 Test::More::plan(skip_all => 'these tests are for testing by the author'); 7 } 8} 9 10 11use strict; 12use warnings; 13 14use FindBin; 15use lib "$FindBin::Bin/lib"; 16 17our $iters; 18 19BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; } 20 21use Test::More tests => 10*$iters; 22use Catalyst::Test 'TestApp'; 23 24if ( $ENV{CAT_BENCHMARK} ) { 25 require Benchmark; 26 Benchmark::timethis( $iters, \&run_tests ); 27} 28else { 29 for ( 1 .. $iters ) { 30 run_tests(); 31 } 32} 33 34sub run_tests { 35 # test direct streaming 36 { 37 ok( my $response = request('http://localhost/streaming'), 'Request' ); 38 ok( $response->is_success, 'Response Successful 2xx' ); 39 is( $response->content_type, 'text/plain', 'Response Content-Type' ); 40 41 SKIP: 42 { 43 if ( $ENV{CATALYST_SERVER} ) { 44 skip "Using remote server", 1; 45 } 46 47 # XXX: Length should be undef here, but HTTP::Request::AsCGI sets it 48 is( $response->content_length, 12, 'Response Content-Length' ); 49 } 50 51 is( $response->content,, <<'EOF', 'Content is a stream' ); 52foo 53bar 54baz 55EOF 56 } 57 58 # test streaming by passing a handle to $c->res->body 59 SKIP: 60 { 61 if ( $ENV{CATALYST_SERVER} ) { 62 skip "Using remote server", 5; 63 } 64 65 my $file = "$FindBin::Bin/lib/TestApp/Controller/Action/Streaming.pm"; 66 my $fh = IO::File->new( $file, 'r' ); 67 my $buffer; 68 if ( defined $fh ) { 69 $fh->read( $buffer, 1024 ); 70 $fh->close; 71 } 72 73 ok( my $response = request('http://localhost/action/streaming/body'), 74 'Request' ); 75 ok( $response->is_success, 'Response Successful 2xx' ); 76 is( $response->content_type, 'text/plain', 'Response Content-Type' ); 77 is( $response->content_length, -s $file, 'Response Content-Length' ); 78 is( $response->content, $buffer, 'Content is read from filehandle' ); 79 } 80} 81