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