1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#!/usr/bin/perl
# vim: filetype=perl
# Make sure that client sessions stay alive while they're waiting for
# sockets. Also test the shutdown order, or more appropriately that
# Client::Keepalive can be shut down with outstanding sockets, without
# the whole program crashing and burning horribly.
use warnings;
use strict;
use lib qw(./mylib ../mylib);
use Test::More tests => 1;
sub POE::Kernel::ASSERT_DEFAULT () { 1 }
use POE;
use POE::Component::Client::Keepalive;
use POE::Component::Resolver;
use Socket qw(AF_INET);
use TestServer;
my $server_port = TestServer->spawn(0);
my $global_cm = POE::Component::Client::Keepalive->new(
resolver => POE::Component::Resolver->new(af_order => [ AF_INET ]),
);
POE::Session->create(
inline_states => {
_start => \&start,
_stop => \&stop,
got_conn => \&got_conn,
}
);
sub start {
my $heap = $_[HEAP];
$global_cm->allocate(
scheme => "http",
addr => "127.0.0.1",
port => $server_port,
event => "got_conn",
context => "first",
);
}
sub got_conn {
my ($heap, $stuff) = @_[HEAP, ARG0];
my $conn = $stuff->{connection};
my $which = $stuff->{context};
ok( defined($conn), "got the connection" );
$global_cm->shutdown() unless $heap->{cm_shutdown}++;
TestServer->shutdown() unless $heap->{ts_shutdown}++;
}
sub stop {
my $heap = $_[HEAP];
$global_cm->shutdown() unless $heap->{cm_shutdown}++;
TestServer->shutdown() unless $heap->{ts_shutdown}++;
}
POE::Kernel->run();
exit;
|