Commit | Line | Data |
50cc3183 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use FindBin; |
42da66a9 |
5 | use lib "$FindBin::Bin/../lib"; |
50cc3183 |
6 | |
7 | our $iters; |
8 | |
6b25e555 |
9 | BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; } |
50cc3183 |
10 | |
6e1254dc |
11 | use Test::More; |
50cc3183 |
12 | use Catalyst::Test 'TestApp'; |
13 | |
14 | if ( $ENV{CAT_BENCHMARK} ) { |
15 | require Benchmark; |
16 | Benchmark::timethis( $iters, \&run_tests ); |
17 | } |
18 | else { |
19 | for ( 1 .. $iters ) { |
20 | run_tests(); |
21 | } |
22 | } |
23 | |
24 | sub run_tests { |
25 | # test direct streaming |
26 | { |
27 | ok( my $response = request('http://localhost/streaming'), 'Request' ); |
28 | ok( $response->is_success, 'Response Successful 2xx' ); |
29 | is( $response->content_type, 'text/plain', 'Response Content-Type' ); |
258733f1 |
30 | is( $response->header('X-Test-Header'), 'valid', 'Headers sent properly' ); |
89ba65d5 |
31 | is( $response->header('X-Test-Header-Call-Count'), 1); |
09ea4a24 |
32 | |
048f45ee |
33 | SKIP: |
34 | { |
35 | if ( $ENV{CATALYST_SERVER} ) { |
36 | skip "Using remote server", 1; |
37 | } |
09ea4a24 |
38 | |
6e1254dc |
39 | ok(!defined $response->content_length, 'No Content-Length for streaming responses'); |
40 | is(length $response->content, 12, 'Response content' ); |
048f45ee |
41 | } |
09ea4a24 |
42 | |
50cc3183 |
43 | is( $response->content,, <<'EOF', 'Content is a stream' ); |
44 | foo |
45 | bar |
46 | baz |
47 | EOF |
48 | } |
49 | |
50 | # test streaming by passing a handle to $c->res->body |
51 | SKIP: |
52 | { |
53 | if ( $ENV{CATALYST_SERVER} ) { |
9c74923d |
54 | skip "Using remote server", 10; |
50cc3183 |
55 | } |
56 | |
0e155123 |
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 ) { |
9c74923d |
61 | $fh->read( $buffer, 2048 ); |
50cc3183 |
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' ); |
258733f1 |
70 | is( $response->header('X-Test-Header'), 'valid', 'Headers sent properly' ); |
89ba65d5 |
71 | is( $response->header('X-Test-Header-Call-Count'), 1); |
50cc3183 |
72 | is( $response->content, $buffer, 'Content is read from filehandle' ); |
9c74923d |
73 | |
74 | ok( $response = request('http://localhost/action/streaming/body_glob'), |
75 | 'Request' ); |
76 | ok( $response->is_success, 'Response Successful 2xx' ); |
77 | is( $response->content_type, 'text/plain', 'Response Content-Type' ); |
78 | is( $response->content_length, -s $file, 'Response Content-Length' ); |
258733f1 |
79 | is( $response->header('X-Test-Header'), 'valid', 'Headers sent properly' ); |
89ba65d5 |
80 | is( $response->header('X-Test-Header-Call-Count'), 1); |
9c74923d |
81 | is( $response->content, $buffer, 'Content is read from filehandle' ); |
50cc3183 |
82 | } |
a9b467d3 |
83 | |
84 | { |
85 | my $size = 128 * 1024; # more than one read with the default chunksize |
86 | |
87 | ok( my $response = request('http://localhost/action/streaming/body_large'), 'Request' ); |
88 | ok( $response->is_success, 'Response Successful 2xx' ); |
89 | is( $response->content_type, 'text/plain', 'Response Content-Type' ); |
258733f1 |
90 | is( $response->header('X-Test-Header'), 'valid', 'Headers sent properly' ); |
89ba65d5 |
91 | is( $response->header('X-Test-Header-Call-Count'), 1); |
a9b467d3 |
92 | is( $response->content_length, $size, 'Response Content-Length' ); |
93 | is( $response->content, "\0" x $size, 'Content is read from filehandle' ); |
94 | } |
50cc3183 |
95 | } |
6e1254dc |
96 | |
97 | done_testing; |