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 | |
0b9d5bf4 |
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 ); |
0b9d5bf4 |
17 | |
50cc3183 |
18 | # new dispatcher: |
19 | # 11 wallclock secs (10.14 usr + 0.20 sys = 10.34 CPU) @ 15.18/s (n=157) |
20 | # old dispatcher (r1486): |
21 | # 11 wallclock secs (10.34 usr + 0.20 sys = 10.54 CPU) @ 13.76/s (n=145) |
22 | } |
23 | else { |
24 | for ( 1 .. $iters ) { |
25 | run_tests(); |
26 | } |
27 | } |
0b9d5bf4 |
28 | |
50cc3183 |
29 | sub run_tests { |
30 | # test auto + local method |
31 | { |
32 | my @expected = qw[ |
33 | TestApp::Controller::Action::Auto->begin |
34 | TestApp::Controller::Action::Auto->auto |
35 | TestApp::Controller::Action::Auto->one |
a0a66cb8 |
36 | TestApp::Controller::Root->end |
50cc3183 |
37 | ]; |
0b9d5bf4 |
38 | |
50cc3183 |
39 | my $expected = join( ", ", @expected ); |
0b9d5bf4 |
40 | |
50cc3183 |
41 | ok( my $response = request('http://localhost/action/auto/one'), 'auto + local' ); |
42 | is( $response->header('X-Catalyst-Executed'), |
43 | $expected, 'Executed actions' ); |
44 | is( $response->content, 'one', 'Content OK' ); |
45 | } |
0b9d5bf4 |
46 | |
50cc3183 |
47 | # test auto + default |
48 | { |
49 | my @expected = qw[ |
50 | TestApp::Controller::Action::Auto->begin |
51 | TestApp::Controller::Action::Auto->auto |
52 | TestApp::Controller::Action::Auto->default |
a0a66cb8 |
53 | TestApp::Controller::Root->end |
50cc3183 |
54 | ]; |
0b9d5bf4 |
55 | |
50cc3183 |
56 | my $expected = join( ", ", @expected ); |
0b9d5bf4 |
57 | |
50cc3183 |
58 | ok( my $response = request('http://localhost/action/auto/anything'), 'auto + default' ); |
59 | is( $response->header('X-Catalyst-Executed'), |
60 | $expected, 'Executed actions' ); |
61 | is( $response->content, 'default', 'Content OK' ); |
62 | } |
0b9d5bf4 |
63 | |
50cc3183 |
64 | # test auto + auto + local |
65 | { |
66 | my @expected = qw[ |
67 | TestApp::Controller::Action::Auto::Deep->begin |
68 | TestApp::Controller::Action::Auto->auto |
69 | TestApp::Controller::Action::Auto::Deep->auto |
70 | TestApp::Controller::Action::Auto::Deep->one |
a0a66cb8 |
71 | TestApp::Controller::Root->end |
50cc3183 |
72 | ]; |
0b9d5bf4 |
73 | |
50cc3183 |
74 | my $expected = join( ", ", @expected ); |
0b9d5bf4 |
75 | |
50cc3183 |
76 | ok( my $response = request('http://localhost/action/auto/deep/one'), 'auto + auto + local' ); |
77 | is( $response->header('X-Catalyst-Executed'), |
78 | $expected, 'Executed actions' ); |
79 | is( $response->content, 'deep one', 'Content OK' ); |
80 | } |
0b9d5bf4 |
81 | |
50cc3183 |
82 | # test auto + auto + default |
83 | { |
84 | my @expected = qw[ |
85 | TestApp::Controller::Action::Auto::Deep->begin |
86 | TestApp::Controller::Action::Auto->auto |
87 | TestApp::Controller::Action::Auto::Deep->auto |
88 | TestApp::Controller::Action::Auto::Deep->default |
a0a66cb8 |
89 | TestApp::Controller::Root->end |
50cc3183 |
90 | ]; |
0b9d5bf4 |
91 | |
50cc3183 |
92 | my $expected = join( ", ", @expected ); |
0b9d5bf4 |
93 | |
50cc3183 |
94 | ok( my $response = request('http://localhost/action/auto/deep/anything'), 'auto + auto + default' ); |
95 | is( $response->header('X-Catalyst-Executed'), |
96 | $expected, 'Executed actions' ); |
97 | is( $response->content, 'deep default', 'Content OK' ); |
98 | } |
0b9d5bf4 |
99 | |
50cc3183 |
100 | # test auto + failing auto + local + end |
101 | { |
102 | my @expected = qw[ |
103 | TestApp::Controller::Action::Auto::Abort->begin |
104 | TestApp::Controller::Action::Auto->auto |
105 | TestApp::Controller::Action::Auto::Abort->auto |
106 | TestApp::Controller::Action::Auto::Abort->end |
107 | ]; |
0b9d5bf4 |
108 | |
50cc3183 |
109 | my $expected = join( ", ", @expected ); |
0b9d5bf4 |
110 | |
50cc3183 |
111 | ok( my $response = request('http://localhost/action/auto/abort/one'), 'auto + failing auto + local' ); |
112 | is( $response->header('X-Catalyst-Executed'), |
113 | $expected, 'Executed actions' ); |
114 | is( $response->content, 'abort end', 'Content OK' ); |
115 | } |
0b9d5bf4 |
116 | |
37d1bca8 |
117 | # test auto + default (bug on invocation of default twice) |
50cc3183 |
118 | { |
119 | my @expected = qw[ |
37d1bca8 |
120 | TestApp::Controller::Action::Auto::Default->begin |
50cc3183 |
121 | TestApp::Controller::Action::Auto->auto |
37d1bca8 |
122 | TestApp::Controller::Action::Auto::Default->auto |
123 | TestApp::Controller::Action::Auto::Default->default |
124 | TestApp::Controller::Action::Auto::Default->end |
50cc3183 |
125 | ]; |
0b9d5bf4 |
126 | |
50cc3183 |
127 | my $expected = join( ", ", @expected ); |
0b9d5bf4 |
128 | |
37d1bca8 |
129 | ok( my $response = request('http://localhost/action/auto/default/moose'), 'auto + default' ); |
50cc3183 |
130 | is( $response->header('X-Catalyst-Executed'), |
131 | $expected, 'Executed actions' ); |
37d1bca8 |
132 | is( $response->content, 'default (auto: 1)', 'Content OK' ); |
50cc3183 |
133 | } |
2688734f |
134 | |
135 | # test detach in auto |
136 | { |
137 | my @expected = qw[ |
138 | TestApp::Controller::Action::Auto::Detach->begin |
139 | TestApp::Controller::Action::Auto->auto |
140 | TestApp::Controller::Action::Auto::Detach->auto |
141 | TestApp::Controller::Root->end |
142 | ]; |
0b9d5bf4 |
143 | |
2688734f |
144 | my $expected = join( ", ", @expected ); |
0b9d5bf4 |
145 | |
2688734f |
146 | ok( my $response = request('http://localhost/action/auto/detach'), 'auto with detach' ); |
147 | is( $response->header('X-Catalyst-Executed'), |
148 | $expected, 'Executed actions' ); |
149 | is( $response->content, 'detach auto', 'Content OK' ); |
150 | } |
151 | |
152 | # test detach in auto forward |
153 | { |
154 | my @expected = qw[ |
155 | TestApp::Controller::Action::Auto::Detach->begin |
156 | TestApp::Controller::Action::Auto->auto |
157 | TestApp::Controller::Action::Auto::Detach->auto |
158 | TestApp::Controller::Action::Auto::Detach->with_forward_detach |
159 | TestApp::Controller::Root->end |
160 | ]; |
0b9d5bf4 |
161 | |
2688734f |
162 | my $expected = join( ", ", @expected ); |
0b9d5bf4 |
163 | |
2688734f |
164 | ok( my $response = request('http://localhost/action/auto/detach?with_forward_detach=1'), 'auto with_forward_detach' ); |
165 | is( $response->header('X-Catalyst-Executed'), |
166 | $expected, 'Executed actions' ); |
167 | is( $response->content, 'detach with_forward_detach', 'Content OK' ); |
168 | } |
169 | |
170 | # test detach in auto forward detach action |
171 | { |
172 | my @expected = qw[ |
173 | TestApp::Controller::Action::Auto::Detach->begin |
174 | TestApp::Controller::Action::Auto->auto |
175 | TestApp::Controller::Action::Auto::Detach->auto |
176 | TestApp::Controller::Action::Auto::Detach->with_forward_detach |
177 | TestApp::Controller::Action::Auto::Detach->detach_action |
178 | TestApp::Controller::Root->end |
179 | ]; |
0b9d5bf4 |
180 | |
2688734f |
181 | my $expected = join( ", ", @expected ); |
0b9d5bf4 |
182 | |
2688734f |
183 | ok( my $response = request('http://localhost/action/auto/detach?with_forward_detach=1&detach_to_action=1'), 'auto with_forward_detach to detach_action' ); |
184 | is( $response->header('X-Catalyst-Executed'), |
185 | $expected, 'Executed actions' ); |
186 | is( $response->content, 'detach_action', 'Content OK' ); |
187 | } |
50cc3183 |
188 | } |
0b9d5bf4 |
189 | |
190 | done_testing; |
191 | |