1#!/usr/bin/perl 2# vim: filetype=perl 3 4use warnings; 5use strict; 6use lib qw(./mylib ../mylib); 7 8sub POE::Kernel::ASSERT_DEFAULT () { 1 } 9 10use Test::More tests => 2; 11use POE; 12use POE::Component::Client::Keepalive; 13use POE::Component::Resolver; 14use Socket qw(AF_INET); 15 16POE::Session->create( 17 inline_states => { 18 _child => sub { }, 19 _start => \&start, 20 _stop => \&crom_count_the_responses, 21 got_resp => \&got_resp, 22 } 23); 24 25POE::Kernel->run(); 26exit; 27 28# Start up! Create a Keepalive component. Request one connection. 29# The request is specially formulated to time out immediately. We 30# should receive no other response (especially not a resolve error 31# like "Host has no address." 32 33sub start { 34 my $heap = $_[HEAP]; 35 36 $heap->{errors} = [ ]; 37 38 $heap->{cm} = POE::Component::Client::Keepalive->new( 39 resolver => POE::Component::Resolver->new(af_order => [ AF_INET ]), 40 ); 41 42 $heap->{cm}->allocate( 43 scheme => "http", 44 addr => "seriously-hoping-this-never-resolves.fail", 45 port => 80, 46 event => "got_resp", 47 context => "moo", 48 timeout => -1, 49 ); 50} 51 52# We received a response. Count it. 53 54sub got_resp { 55 my ($heap, $stuff) = @_[HEAP, ARG0]; 56 push @{$heap->{errors}}, $stuff->{function}; 57} 58 59# End of run. We're good if we receive only one timeout response. 60 61sub crom_count_the_responses { 62 my @errors = @{$_[HEAP]{errors}}; 63 ok( 64 @errors == 1, 65 "should have received one response (actual=" . @errors . ")" 66 ); 67 ok( $errors[0] eq "connect", "the one response was a connect error"); 68} 69