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 | |
13 | use Test::More tests => 8*$iters; |
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' ); |
32 | is( $response->content,, <<'EOF', 'Content is a stream' ); |
33 | foo |
34 | bar |
35 | baz |
36 | EOF |
37 | } |
38 | |
39 | # test streaming by passing a handle to $c->res->body |
40 | SKIP: |
41 | { |
42 | if ( $ENV{CATALYST_SERVER} ) { |
43 | skip "Using remote server", 4; |
44 | } |
45 | |
a2e038a1 |
46 | my $file = "$FindBin::Bin/01use.t"; |
50cc3183 |
47 | my $fh = IO::File->new( $file, 'r' ); |
48 | my $buffer; |
49 | if ( defined $fh ) { |
50 | $fh->read( $buffer, 1024 ); |
51 | $fh->close; |
52 | } |
53 | |
54 | ok( my $response = request('http://localhost/action/streaming/body'), |
55 | 'Request' ); |
56 | ok( $response->is_success, 'Response Successful 2xx' ); |
57 | is( $response->content_type, 'text/plain', 'Response Content-Type' ); |
58 | is( $response->content, $buffer, 'Content is read from filehandle' ); |
59 | } |
60 | } |