X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Foptional_threads.t;fp=t%2Foptional_threads.t;h=baa40894dbed44bb1bb49e14157c62e6bf2b6eef;hb=4a41d5d1ec3187cc41e15767b21c14b2aee31740;hp=0000000000000000000000000000000000000000;hpb=2757db2c7c600c8a0b8e2b4366f38c97804c2844;p=catagits%2FCatalyst-Runtime.git diff --git a/t/optional_threads.t b/t/optional_threads.t new file mode 100644 index 0000000..baa4089 --- /dev/null +++ b/t/optional_threads.t @@ -0,0 +1,55 @@ +#!perl + +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'; +sub request { + my $thr = threads->new( + sub { Catalyst::Test::local_request('TestApp',@_) }, + @_ + ); + $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' ); +}