X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=t%2Foptional_threads.t;h=3d7dd8abf47e1809d6a8033e04704bbf875eb263;hp=50a6ecddb355e3899c36e96c594f6d81fa0b3d84;hb=4e45fa288ea80bf2a4587dd2278c784286aafdc3;hpb=a2e038a1e9cbc0f1ea32b7087e6b47efe3af082f diff --git a/t/optional_threads.t b/t/optional_threads.t index 50a6ecd..3d7dd8a 100644 --- a/t/optional_threads.t +++ b/t/optional_threads.t @@ -1,53 +1,54 @@ -#!perl - -use strict; -use warnings; - -use FindBin; -use lib "$FindBin::Bin/lib"; - -use Test::More; -use Catalyst::Test 'TestApp'; -use Catalyst::Request; -use Config; - -plan skip_all => 'set TEST_THREADS to enable this test' - unless $ENV{TEST_THREADS}; - -if ( $Config{useithreads} && !$ENV{CATALYST_SERVER} ) { - require threads; - plan tests => 3; -} -else { - if ( $ENV{CATALYST_SERVER} ) { - plan skip_all => 'Using remote server'; - } - else { - plan skip_all => 'Needs a Perl with ithreads enabled'; - } -} - -no warnings 'redefine'; -sub request { - my $thr = threads->new( - sub { TestApp->run(@_) }, - @_ - ); - $thr->join; -} - -# test that running inside a thread works ok -{ - my @expected = qw[ - TestApp::Controller::Action::Default->begin - TestApp::Controller::Action::Default->default - TestApp::View::Dump::Request->process - TestApp->end - ]; - - my $expected = join( ", ", @expected ); - - ok( my $response = request('http://localhost/action/default'), 'Request' ); - ok( $response->is_success, 'Response Successful 2xx' ); - is( $response->header('X-Catalyst-Executed'), $expected, 'Executed actions' ); -} +use strict; +use warnings; + +use Test::More; +BEGIN { + plan skip_all => 'set TEST_THREADS to enable this test' + unless $ENV{TEST_THREADS}; +} + +use FindBin; +use lib "$FindBin::Bin/lib"; +use Catalyst::Test 'TestApp'; +use Catalyst::Request; +use Config; +use HTTP::Response; + +if ( $Config{useithreads} && !$ENV{CATALYST_SERVER} ) { + require threads; + plan tests => 3; +} +else { + if ( $ENV{CATALYST_SERVER} ) { + plan skip_all => 'Using remote server'; + } + else { + plan skip_all => 'Needs a Perl with ithreads enabled'; + } +} + +no warnings 'redefine'; +my $request_code = \&request; +*request = sub { + my $thr = threads->new( + sub { $request_code->(@_) }, + @_ + ); + $thr->join; +}; + +# test that running inside a thread works ok +{ + my @expected = qw[ + TestApp::Controller::Action::Default->begin + TestApp::Controller::Action::Default->default + TestApp::View::Dump::Request->process + TestApp::Controller::Root->end + ]; + + my $expected = join( ", ", @expected ); + + ok( my $response = request('http://localhost/action/default'), 'Request' ); + ok( $response->is_success, 'Response Successful 2xx' ); + is( $response->header('X-Catalyst-Executed'), $expected, 'Executed actions' ); +}