PAGI-Server

 view release on metacpan or  search on metacpan

t/integration/runner-server.t  view on Meta::CPAN

#!/usr/bin/env perl

# =============================================================================
# Runner/Server integration tests
#
# PROVENANCE: These subtests were relocated from PAGI-Tools to PAGI-Server
# because they exercise a real PAGI::Server (real sockets, real event loop,
# SSL-cert rejection, PID-file lifecycle with a forked server process).
#
# Original sources:
#   - Subtests 1-6: PAGI-Tools t/runner.t
#   - Subtest 7:    PAGI-Tools t/25-runner-production.t
#
# PAGI::Server::Runner ships in this distribution. The integration tests
# exercise toolkit modules (PAGI::App::*, PAGI::Test::Client) that live in
# PAGI-Tools. Run with PAGI-Tools lib bridged for those modules:
#   PERL5LIB=/path/to/PAGI-Tools/lib:$PERL5LIB prove -lv t/integration/runner-server.t
# =============================================================================

use strict;
use warnings;
use Test2::V0;
use FindBin;
use lib "$FindBin::Bin/../../lib";

plan skip_all => "Server integration tests not supported on Windows" if $^O eq 'MSWin32';

use IO::Async::Loop;
use Net::Async::HTTP;
use Future::AsyncAwait;
use File::Temp qw(tempdir tempfile);

use PAGI::Server;
use PAGI::Server::Runner;

# ---------------------------------------------------------------------------
# SOURCE: t/runner.t
# SUBTEST: 'load_server dies without app'
# NOTE: This tested PAGI::Server->new(app => undef) dying, not Runner logic.
#       Runner::load_server does NOT die when app is undef — it passes undef
#       to the server constructor. The die came from PAGI::Server.
# ---------------------------------------------------------------------------
subtest 'load_server dies without app' => sub {
    my $runner = PAGI::Server::Runner->new;

    like(
        dies { $runner->load_server },
        qr/app/i,
        'dies without app'
    );
};

# ---------------------------------------------------------------------------
# SOURCE: t/runner.t
# SUBTEST: 'integration: server responds to requests'
# ---------------------------------------------------------------------------
subtest 'integration: server responds to requests' => sub {
    my $loop = IO::Async::Loop->new;

    my $runner = PAGI::Server::Runner->new(port => 0, quiet => 1);
    $runner->{app_spec} = "$FindBin::Bin/../../examples/01-hello-http/app.pl";
    $runner->{default_middleware} = 0;  # Disable Lint for test
    $runner->prepare_app;
    my $server = $runner->load_server;

    $loop->add($server);



( run in 0.927 second using v1.01-cache-2.11-cpan-84de2e75c66 )