Feersum

 view release on metacpan or  search on metacpan

xt/runner-18-features.t  view on Meta::CPAN

select undef, undef, undef, 1.5 * TIMEOUT_MULT;

my $body4;
my $cv4 = AE::cv;
my $c4; $c4 = simple_client GET => '/', port => $port4, sub {
    ($body4) = @_;
    $cv4->send;
    undef $c4;
};
$cv4->recv;
ok $body4, "preload_app=0 server responds";
like $body4, qr/^pid=\d+/, "preload_app=0 worker has its own pid";

reap_server($pid4);
is $? & 127, 0, "preload_app=0 shut down cleanly";

###############################################################################
# Test 5: access_log callback fires with correct args
###############################################################################

my $log_dir = tempdir(CLEANUP => 1);
my $log_file = "$log_dir/access.log";

my (undef, $port5) = get_listen_socket();
my $pid5 = fork;
push @_kill_on_exit, $pid5 if $pid5;
die "fork: $!" unless defined $pid5;
if (!$pid5) {
    require Feersum::Runner;
    eval {
        Feersum::Runner->new(
            listen     => ["localhost:$port5"],
            quiet      => 1,
            access_log => sub {
                my ($method, $uri, $elapsed) = @_;
                open my $fh, '>>', $log_file;
                print $fh "$method $uri $elapsed\n";
                close $fh;
            },
            app => sub {
                my $r = shift;
                $r->send_response(200, ['Content-Type'=>'text/plain'], \"ok\n");
            },
        )->run();
    };
    POSIX::_exit(0);
}

select undef, undef, undef, 1.5 * TIMEOUT_MULT;

my $cv5 = AE::cv;
my $c5; $c5 = simple_client GET => '/test-path', port => $port5, sub {
    $cv5->send; undef $c5;
};
$cv5->recv;

# Give guard time to fire (response_guard fires after send completes)
select undef, undef, undef, 0.5 * TIMEOUT_MULT;

ok -f $log_file, "access_log file created";
my $log_content = do { local (@ARGV, $/) = ($log_file); <> } // '';
like $log_content, qr{^GET /test-path \d}, "access_log captured method, uri, elapsed";

reap_server($pid5);
is $? & 127, 0, "access_log test shut down cleanly";



( run in 0.717 second using v1.01-cache-2.11-cpan-194103478d8 )