On Tue, 2007-07-31 at 12:33 +0400, Ivan Fomichev wrote:
> Hello,
> 
> I intend to write a script, that would start the test server as a
> child process and then run tests. The thing I'm failing to do is to
> get output from the test server in order to determine, when the server
> has started.
> 
> The problem is that test server doesn't print its prompt ("You can
> connect to your server at http://localhost:3000";) when run as a child
> process :-(
> 
> I dug Catalyst's sources, but didn't understood much. I put 'sleep' in
> parent process for now, but I don't like it. Could anyone suggest an
> adequate work-around? Thank you in advance.
> 
> 8<------------------------script/myapp_regtest.pl--------------------------
> #!/usr/bin/perl
> use strict;
> use warnings;
> 
> use Config::IniFiles;
> use File::Spec::Functions;
> use FindBin;
> use POSIX qw/ :signal_h /;
> 
> my $ini = Config::IniFiles->new( -file => catfile( $FindBin::Bin,
> updir, 'myapp_regtest.ini' ) );
> $ENV{MYAPP_DSN} = $ini->val( 'database', 'dsn' );
> 
> defined ( my $catalyst_pid = open(CHILD, '-|') )
>     or die "cannot fork: $!";
> 
> if ( !$catalyst_pid ) {
>     my $port = $ini->val( 'catalyst', 'port' );
>     exec( catfile( $FindBin::Bin, 'myapp_server.pl' ), '-p', $port );
> }
> 
> print scalar <CHILD>;
> 
> my $lib = catdir( $FindBin::Bin, updir, 'lib' );
> chdir catdir( $FindBin::Bin, updir );
> system( 'prove', '--lib', $lib, 't' );
> 
> kill SIGINT, $catalyst_pid;
> 8<----------------------------------END------------------------------------
> 
> Regards,
> Ivan
> 

I've approached this by doing a GET on http://localhost:3000 until it
succeeds or times out:

    my $ua = LWP::UserAgent->new();
    my $wait_secs = 30;
    for my $i (1 .. $wait_secs) {
        my $r = $ua->get("http://localhost:"; . $self->{port});
        last if $r->is_success;
        die "Failed to start test server" if $i == $wait_secs;
        sleep(1);
    }

-- 

Jon


_______________________________________________
List: [email protected]
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to