Subject: | tests don't detect failure to deliver connection failure events |
POE::XS::Loop::Poll 0.003 has an error where connect() failures weren't
generating an event.
The attached file is a test script that detects the error (and succeeds)
or times out and fails.
One possible false negative is if there is a service listening on the
given port.
Subject: | 10connect.t |
#!perl -w
use strict;
use Test::More tests => 1;
# POE::XS::Loop::Poll wasn't handling errors correctly, this was
# particularly noticable for connect() failures, so check connection
# failures are handled correctly
use POE::Kernel { loop => 'POE::XS::Loop::Poll' };
use POE qw( Wheel::ReadWrite Component::Client::TCP );
POE::Session->create
(
inline_states =>
{
_start => sub {
$poe_kernel->alias_set('watcher');
$_[HEAP]{alarm} = $poe_kernel->alarm_set(timeout => time() + 10);
},
timeout => sub {
$poe_kernel->post(client => 'shutdown');
fail("timeout for connection");
},
shutdown => sub {
$poe_kernel->alarm_remove($_[HEAP]{alarm});
},
}
);
POE::Component::Client::TCP->new
(
RemotePort => 32767, # something unused
RemoteAddress => '127.0.0.1',
Alias => 'client',
Connected => sub {
fail("should have failed to connect");
},
ConnectError => sub {
$poe_kernel->post(watcher => 'shutdown');
pass("expected connection failure occurred");
},
ServerInput => sub {
warn "ServerInput called unexpectedly\n";
},
);
POE::Kernel->run();