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