Added some stress testing
[catagits/Catalyst-Runtime.git] / t / live / component / controller / action / streaming.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use FindBin;
7 use lib "$FindBin::Bin/../../../lib";
8
9 use Test::More tests => 80;
10 use Catalyst::Test 'TestApp';
11
12 for ( 1 .. 10 ) {
13
14     # test direct streaming
15     {
16         ok( my $response = request('http://localhost/streaming'), 'Request' );
17         ok( $response->is_success, 'Response Successful 2xx' );
18         is( $response->content_type, 'text/plain', 'Response Content-Type' );
19         is( $response->content,, <<'EOF', 'Content is a stream' );
20 foo
21 bar
22 baz
23 EOF
24     }
25
26     # test streaming by passing a handle to $c->res->body
27   SKIP:
28     {
29         if ( $ENV{CATALYST_SERVER} ) {
30             skip "Using remote server", 4;
31         }
32
33         my $file = "$FindBin::Bin/../../../../01use.t";
34         my $fh = IO::File->new( $file, 'r' );
35         my $buffer;
36         if ( defined $fh ) {
37             $fh->read( $buffer, 1024 );
38             $fh->close;
39         }
40
41         ok( my $response = request('http://localhost/action/streaming/body'),
42             'Request' );
43         ok( $response->is_success, 'Response Successful 2xx' );
44         is( $response->content_type, 'text/plain', 'Response Content-Type' );
45         is( $response->content, $buffer, 'Content is read from filehandle' );
46     }
47 }