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