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 => 18*$iters; |
14 | use Catalyst::Test 'TestApp'; |
15 | |
16 | if ( $ENV{CAT_BENCHMARK} ) { |
17 | require Benchmark; |
18 | Benchmark::timethis( $iters, \&run_tests ); |
19 | |
20 | # new dispatcher: |
21 | # 11 wallclock secs (10.14 usr + 0.20 sys = 10.34 CPU) @ 15.18/s (n=157) |
22 | # old dispatcher (r1486): |
23 | # 11 wallclock secs (10.34 usr + 0.20 sys = 10.54 CPU) @ 13.76/s (n=145) |
24 | } |
25 | else { |
26 | for ( 1 .. $iters ) { |
27 | run_tests(); |
28 | } |
29 | } |
30 | |
31 | sub run_tests { |
32 | # test auto + local method |
33 | { |
34 | my @expected = qw[ |
35 | TestApp::Controller::Action::Auto->begin |
36 | TestApp::Controller::Action::Auto->auto |
37 | TestApp::Controller::Action::Auto->one |
c7ded7aa |
38 | TestApp->end |
50cc3183 |
39 | ]; |
40 | |
41 | my $expected = join( ", ", @expected ); |
42 | |
43 | ok( my $response = request('http://localhost/action/auto/one'), 'auto + local' ); |
44 | is( $response->header('X-Catalyst-Executed'), |
45 | $expected, 'Executed actions' ); |
46 | is( $response->content, 'one', 'Content OK' ); |
47 | } |
48 | |
49 | # test auto + default |
50 | { |
51 | my @expected = qw[ |
52 | TestApp::Controller::Action::Auto->begin |
53 | TestApp::Controller::Action::Auto->auto |
54 | TestApp::Controller::Action::Auto->default |
c7ded7aa |
55 | TestApp->end |
50cc3183 |
56 | ]; |
57 | |
58 | my $expected = join( ", ", @expected ); |
59 | |
60 | ok( my $response = request('http://localhost/action/auto/anything'), 'auto + default' ); |
61 | is( $response->header('X-Catalyst-Executed'), |
62 | $expected, 'Executed actions' ); |
63 | is( $response->content, 'default', 'Content OK' ); |
64 | } |
65 | |
66 | # test auto + auto + local |
67 | { |
68 | my @expected = qw[ |
69 | TestApp::Controller::Action::Auto::Deep->begin |
70 | TestApp::Controller::Action::Auto->auto |
71 | TestApp::Controller::Action::Auto::Deep->auto |
72 | TestApp::Controller::Action::Auto::Deep->one |
c7ded7aa |
73 | TestApp->end |
50cc3183 |
74 | ]; |
75 | |
76 | my $expected = join( ", ", @expected ); |
77 | |
78 | ok( my $response = request('http://localhost/action/auto/deep/one'), 'auto + auto + local' ); |
79 | is( $response->header('X-Catalyst-Executed'), |
80 | $expected, 'Executed actions' ); |
81 | is( $response->content, 'deep one', 'Content OK' ); |
82 | } |
83 | |
84 | # test auto + auto + default |
85 | { |
86 | my @expected = qw[ |
87 | TestApp::Controller::Action::Auto::Deep->begin |
88 | TestApp::Controller::Action::Auto->auto |
89 | TestApp::Controller::Action::Auto::Deep->auto |
90 | TestApp::Controller::Action::Auto::Deep->default |
c7ded7aa |
91 | TestApp->end |
50cc3183 |
92 | ]; |
93 | |
94 | my $expected = join( ", ", @expected ); |
95 | |
96 | ok( my $response = request('http://localhost/action/auto/deep/anything'), 'auto + auto + default' ); |
97 | is( $response->header('X-Catalyst-Executed'), |
98 | $expected, 'Executed actions' ); |
99 | is( $response->content, 'deep default', 'Content OK' ); |
100 | } |
101 | |
102 | # test auto + failing auto + local + end |
103 | { |
104 | my @expected = qw[ |
105 | TestApp::Controller::Action::Auto::Abort->begin |
106 | TestApp::Controller::Action::Auto->auto |
107 | TestApp::Controller::Action::Auto::Abort->auto |
108 | TestApp::Controller::Action::Auto::Abort->end |
109 | ]; |
110 | |
111 | my $expected = join( ", ", @expected ); |
112 | |
113 | ok( my $response = request('http://localhost/action/auto/abort/one'), 'auto + failing auto + local' ); |
114 | is( $response->header('X-Catalyst-Executed'), |
115 | $expected, 'Executed actions' ); |
116 | is( $response->content, 'abort end', 'Content OK' ); |
117 | } |
118 | |
37d1bca8 |
119 | # test auto + default (bug on invocation of default twice) |
50cc3183 |
120 | { |
121 | my @expected = qw[ |
37d1bca8 |
122 | TestApp::Controller::Action::Auto::Default->begin |
50cc3183 |
123 | TestApp::Controller::Action::Auto->auto |
37d1bca8 |
124 | TestApp::Controller::Action::Auto::Default->auto |
125 | TestApp::Controller::Action::Auto::Default->default |
126 | TestApp::Controller::Action::Auto::Default->end |
50cc3183 |
127 | ]; |
128 | |
129 | my $expected = join( ", ", @expected ); |
130 | |
37d1bca8 |
131 | ok( my $response = request('http://localhost/action/auto/default/moose'), 'auto + default' ); |
50cc3183 |
132 | is( $response->header('X-Catalyst-Executed'), |
133 | $expected, 'Executed actions' ); |
37d1bca8 |
134 | is( $response->content, 'default (auto: 1)', 'Content OK' ); |
50cc3183 |
135 | } |
136 | } |