avoid using deprecated subs in threads test
[catagits/Catalyst-Runtime.git] / t / optional_lighttpd-fastcgi-non-root.t
CommitLineData
3b6a7b7f 1use strict;
2use warnings;
3
4853fb50 4use Test::More;
5BEGIN {
6 plan skip_all => 'set TEST_LIGHTTPD to enable this test'
7 unless $ENV{TEST_LIGHTTPD};
8}
9
3b6a7b7f 10use File::Path;
3b6a7b7f 11use FindBin;
12use IO::Socket;
f3d2ec61 13use Config ();
3b6a7b7f 14
8ae46e98 15BEGIN {
16 eval "use FCGI";
17 plan skip_all => 'FCGI required' if $@;
ec904766 18
8ae46e98 19 eval "use File::Copy::Recursive";
20 plan skip_all => 'File::Copy::Recursive required' if $@;
3b6a7b7f 21
8ae46e98 22 eval "use Test::Harness";
23 plan skip_all => 'Test::Harness required' if $@;
24}
3b6a7b7f 25
8ae46e98 26use lib 't/lib';
27use MakeTestApp;
357cc417 28
b71fcc0f 29my $lighttpd_bin = $ENV{LIGHTTPD_BIN} || `which lighttpd`;
30chomp $lighttpd_bin;
31
ec904766 32plan skip_all => 'Please set LIGHTTPD_BIN to the path to lighttpd'
381e2cab 33 unless $lighttpd_bin && -x $lighttpd_bin;
3b6a7b7f 34
35plan tests => 1;
36
8ae46e98 37make_test_app;
3b6a7b7f 38
39# Create a temporary lighttpd config
40my $docroot = "$FindBin::Bin/../t/tmp";
41my $port = 8529;
42
43# Clean up docroot path
f3d2ec61 44$docroot =~ s{/t/\.\.}{};
45
46my $perl5lib = join($Config::Config{path_sep}, "$docroot/../../lib", $ENV{PERL5LIB} || ());
3b6a7b7f 47
3f5f2699 48my $conf = <<"END";
3b6a7b7f 49# basic lighttpd config file for testing fcgi+catalyst
50server.modules = (
51 "mod_access",
52 "mod_fastcgi",
159eb4bb 53 "mod_rewrite",
3b6a7b7f 54 "mod_accesslog"
55)
56
57server.document-root = "$docroot"
58
59server.errorlog = "$docroot/error.log"
60accesslog.filename = "$docroot/access.log"
61
62server.bind = "127.0.0.1"
63server.port = $port
64
159eb4bb 65# Work around inability to hit http://localhost/deep/path
88e5a8b0 66# without a trailing slash
159eb4bb 67url.rewrite = ( "deep/path\$" => "deep/path/" )
68
3b6a7b7f 69# catalyst app specific fcgi setup
70fastcgi.server = (
71 "/deep/path" => (
72 "FastCgiTest" => (
43ebabf5 73 "socket" => "$docroot/test.socket",
74 "check-local" => "disable",
75 "bin-path" => "$docroot/TestApp/script/testapp_fastcgi.pl",
76 "min-procs" => 1,
77 "max-procs" => 1,
78 "idle-timeout" => 20,
79 "bin-environment" => (
f3d2ec61 80 "PERL5LIB" => "$perl5lib"
43ebabf5 81 )
3b6a7b7f 82 )
83 )
84)
3f5f2699 85END
3b6a7b7f 86
88e5a8b0 87open(my $lightconf, '>', "$docroot/lighttpd.conf")
357cc417 88 or die "Can't open $docroot/lighttpd.conf: $!";
3f5f2699 89print {$lightconf} $conf or die "Write error: $!";
90close $lightconf;
3b6a7b7f 91
88e5a8b0 92my $pid = open my $lighttpd, "$lighttpd_bin -D -f $docroot/lighttpd.conf 2>&1 |"
3b6a7b7f 93 or die "Unable to spawn lighttpd: $!";
88e5a8b0 94
3b6a7b7f 95# wait for it to start
3b6a7b7f 96while ( check_port( 'localhost', $port ) != 1 ) {
357cc417 97 diag "Waiting for server to start...";
3b6a7b7f 98 sleep 1;
99}
100
101# run the testsuite against the server
102$ENV{CATALYST_SERVER} = "http://localhost:$port/deep/path";
357cc417 103
a68314c2 104my @tests = (shift) || glob('t/aggregate/live_*');
357cc417 105eval {
106 runtests(@tests);
107};
108ok(!$@, 'lighttpd tests ran OK');
3b6a7b7f 109
110# shut it down
111kill 'INT', $pid;
112close $lighttpd;
113
114# clean up
115rmtree "$FindBin::Bin/../t/tmp" if -d "$FindBin::Bin/../t/tmp";
116
3b6a7b7f 117sub check_port {
118 my ( $host, $port ) = @_;
119
120 my $remote = IO::Socket::INET->new(
121 Proto => "tcp",
122 PeerAddr => $host,
123 PeerPort => $port
124 );
125 if ($remote) {
126 close $remote;
127 return 1;
128 }
129 else {
130 return 0;
131 }
3f5f2699 132}