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