first cut at :ChildOf
[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
13\r
ae6eea2d 14plan skip_all => 'set TEST_THREADS to enable this test'\r
15 unless $ENV{TEST_THREADS};\r
16\r
fbcc39ad 17if ( $Config{useithreads} && !$ENV{CATALYST_SERVER} ) {\r
18 require threads;\r
19 plan tests => 3;\r
20}\r
21else {\r
22 if ( $ENV{CATALYST_SERVER} ) {\r
23 plan skip_all => 'Using remote server';\r
24 }\r
25 else {\r
26 plan skip_all => 'Needs a Perl with ithreads enabled';\r
27 }\r
28}\r
29 \r
30no warnings 'redefine';\r
31sub request {\r
32 my $thr = threads->new( \r
33 sub { TestApp->run(@_) },\r
34 @_ \r
35 );\r
36 $thr->join;\r
37}\r
38\r
39# test that running inside a thread works ok\r
40{\r
41 my @expected = qw[\r
42 TestApp::Controller::Action::Default->begin\r
43 TestApp::Controller::Action::Default->default\r
44 TestApp::View::Dump::Request->process\r
b0652c9d 45 TestApp->end\r
fbcc39ad 46 ];\r
47\r
48 my $expected = join( ", ", @expected );\r
49 \r
50 ok( my $response = request('http://localhost/action/default'), 'Request' );\r
51 ok( $response->is_success, 'Response Successful 2xx' );\r
52 is( $response->header('X-Catalyst-Executed'), $expected, 'Executed actions' );\r
53}\r