why not just add to the maddness if its already there?
[catagits/Catalyst-Runtime.git] / t / optional_threads.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 BEGIN {
8     plan skip_all => 'set TEST_THREADS to enable this test'
9         unless $ENV{TEST_THREADS};
10 }
11
12 use FindBin;
13 use lib "$FindBin::Bin/lib";
14 use Catalyst::Test 'TestApp';
15 use Catalyst::Request;
16 use Config;
17 use HTTP::Response;
18
19 if ( $Config{useithreads} && !$ENV{CATALYST_SERVER} ) {
20     require threads;
21     plan tests => 3;
22 }
23 else {
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  
32 no warnings 'redefine';
33 sub 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
47         TestApp::Controller::Root->end
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 }