Added a benchmark to the auto test, CAT_BENCHMARK=1
[catagits/Catalyst-Runtime.git] / t / live / component / controller / action / auto.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use FindBin;
7 use lib "$FindBin::Bin/../../../lib";
8
9 use Test::More tests => 180;
10 use Catalyst::Test 'TestApp';
11
12 if ( $ENV{CAT_BENCHMARK} ) {
13     require Benchmark;
14     Benchmark::timethis( -10, \&run_tests );
15     
16     # new dispatcher:
17     # 11 wallclock secs (10.14 usr +  0.20 sys = 10.34 CPU) @ 15.18/s (n=157)
18     # old dispatcher (r1486):
19     # 11 wallclock secs (10.34 usr +  0.20 sys = 10.54 CPU) @ 13.76/s (n=145)
20 }
21 else {
22     for ( 1 .. 10 ) {
23         run_tests();
24     }
25 }
26     
27 sub run_tests {
28     # test auto + local method
29     {
30         my @expected = qw[
31           TestApp::Controller::Action::Auto->begin
32           TestApp::Controller::Action::Auto->auto
33           TestApp::Controller::Action::Auto->one
34         ];
35     
36         my $expected = join( ", ", @expected );
37     
38         ok( my $response = request('http://localhost/action/auto/one'), 'auto + local' );
39         is( $response->header('X-Catalyst-Executed'),
40             $expected, 'Executed actions' );
41         is( $response->content, 'one', 'Content OK' );
42     }
43     
44     # test auto + default
45     {
46         my @expected = qw[
47           TestApp::Controller::Action::Auto->begin
48           TestApp::Controller::Action::Auto->auto
49           TestApp::Controller::Action::Auto->default
50         ];
51     
52         my $expected = join( ", ", @expected );
53     
54         ok( my $response = request('http://localhost/action/auto/anything'), 'auto + default' );
55         is( $response->header('X-Catalyst-Executed'),
56             $expected, 'Executed actions' );
57         is( $response->content, 'default', 'Content OK' );
58     }
59     
60     # test auto + auto + local
61     {
62         my @expected = qw[
63           TestApp::Controller::Action::Auto::Deep->begin
64           TestApp::Controller::Action::Auto->auto
65           TestApp::Controller::Action::Auto::Deep->auto
66           TestApp::Controller::Action::Auto::Deep->one
67         ];
68     
69         my $expected = join( ", ", @expected );
70     
71         ok( my $response = request('http://localhost/action/auto/deep/one'), 'auto + auto + local' );
72         is( $response->header('X-Catalyst-Executed'),
73             $expected, 'Executed actions' );
74         is( $response->content, 'deep one', 'Content OK' );
75     }
76     
77     # test auto + auto + default
78     {
79         my @expected = qw[
80           TestApp::Controller::Action::Auto::Deep->begin
81           TestApp::Controller::Action::Auto->auto
82           TestApp::Controller::Action::Auto::Deep->auto
83           TestApp::Controller::Action::Auto::Deep->default
84         ];
85     
86         my $expected = join( ", ", @expected );
87     
88         ok( my $response = request('http://localhost/action/auto/deep/anything'), 'auto + auto + default' );
89         is( $response->header('X-Catalyst-Executed'),
90             $expected, 'Executed actions' );
91         is( $response->content, 'deep default', 'Content OK' );
92     }
93     
94     # test auto + failing auto + local + end
95     {
96         my @expected = qw[
97           TestApp::Controller::Action::Auto::Abort->begin
98           TestApp::Controller::Action::Auto->auto
99           TestApp::Controller::Action::Auto::Abort->auto
100           TestApp::Controller::Action::Auto::Abort->end
101         ];
102     
103         my $expected = join( ", ", @expected );
104     
105         ok( my $response = request('http://localhost/action/auto/abort/one'), 'auto + failing auto + local' );
106         is( $response->header('X-Catalyst-Executed'),
107             $expected, 'Executed actions' );
108         is( $response->content, 'abort end', 'Content OK' );
109     }
110     
111     # test auto + failing auto + default + end
112     {
113         my @expected = qw[
114           TestApp::Controller::Action::Auto::Abort->begin
115           TestApp::Controller::Action::Auto->auto
116           TestApp::Controller::Action::Auto::Abort->auto
117           TestApp::Controller::Action::Auto::Abort->end
118         ];
119     
120         my $expected = join( ", ", @expected );
121     
122         ok( my $response = request('http://localhost/action/auto/abort/anything'), 'auto + failing auto + default' );
123         is( $response->header('X-Catalyst-Executed'),
124             $expected, 'Executed actions' );
125         is( $response->content, 'abort end', 'Content OK' );
126     }
127 }