applied elapsed time handling patch from Emanuele Zeppieri
[catagits/Catalyst-Runtime.git] / t / optional_threads.t
CommitLineData
fbcc39ad 1#!perl\r
2\r
3use strict;\r
4use warnings;\r
5\r
6use FindBin;\r
a2e038a1 7use lib "$FindBin::Bin/lib";\r
fbcc39ad 8\r
9use Test::More;\r
10use Catalyst::Test 'TestApp';\r
11use Catalyst::Request;\r
12use Config;\r
7a2005ce 13use HTTP::Response;\r
fbcc39ad 14\r
ae6eea2d 15plan skip_all => 'set TEST_THREADS to enable this test'\r
16 unless $ENV{TEST_THREADS};\r
17\r
fbcc39ad 18if ( $Config{useithreads} && !$ENV{CATALYST_SERVER} ) {\r
19 require threads;\r
20 plan tests => 3;\r
21}\r
22else {\r
23 if ( $ENV{CATALYST_SERVER} ) {\r
24 plan skip_all => 'Using remote server';\r
25 }\r
26 else {\r
27 plan skip_all => 'Needs a Perl with ithreads enabled';\r
28 }\r
29}\r
30 \r
31no warnings 'redefine';\r
32sub request {\r
33 my $thr = threads->new( \r
7a2005ce 34 sub { Catalyst::Test::local_request('TestApp',@_) },\r
fbcc39ad 35 @_ \r
36 );\r
37 $thr->join;\r
38}\r
39\r
40# test that running inside a thread works ok\r
41{\r
42 my @expected = qw[\r
43 TestApp::Controller::Action::Default->begin\r
44 TestApp::Controller::Action::Default->default\r
45 TestApp::View::Dump::Request->process\r
b0652c9d 46 TestApp->end\r
fbcc39ad 47 ];\r
48\r
49 my $expected = join( ", ", @expected );\r
50 \r
51 ok( my $response = request('http://localhost/action/default'), 'Request' );\r
52 ok( $response->is_success, 'Response Successful 2xx' );\r
53 is( $response->header('X-Catalyst-Executed'), $expected, 'Executed actions' );\r
54}\r