31fc26f3dcbb3e42d05494a46aa9430a71bebeb8
[catagits/Catalyst-Runtime.git] / t / start_dev_server.t
1 use Test::More tests => 1;
2 use strict;
3 use warnings;
4 use Catalyst::Engine::HTTP;
5 use File::Temp qw/ tempdir tmpnam /;
6 use FindBin qw/$Bin/;
7 use File::Spec;
8 use lib "$Bin/TestApp/lib";
9 use TestApp;
10 use Test::WWW::Mechanize;
11
12 my $dir = tempdir(); # CLEANUP => 1 );
13 my $devnull = File::Spec->devnull;
14
15 my $server_path   = File::Spec->catfile('script', 'testapp_server.pl');
16 my $port = int(rand(10000)) + 40000; # get random port between 40000-50000
17
18 my $childpid = fork();
19 die "fork() error, cannot continue" unless defined($childpid);
20
21 if ($childpid == 0) {
22   system("$^X $server_path -p $port > $devnull 2>&1");
23   exit; # just for sure; we should never got here
24 }
25
26 sleep 10; #wait for catalyst application to start
27 my $mech = Test::WWW::Mechanize->new;
28 $mech->get_ok( "http://localhost:" . $port );
29
30 kill 'KILL', $childpid;
31
32