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
|
use Test::More;
use strict;
use warnings;
use IO::Socket::INET;
use t::Util;
use Net::Proxy;
plan tests => my $tests = 1;
# lock 2 ports
my @free = find_free_ports(2);
SKIP: {
skip "Not enough available ports", $tests if @free < 2;
my ( $proxy_port, $server_port ) = @free;
my $pid = fork;
SKIP: {
skip "fork failed", $tests if !defined $pid;
if ( $pid == 0 ) {
# the child process runs the proxy
my $proxy = Net::Proxy->new(
{ in => {
type => 'tcp',
host => 'localhost',
port => $proxy_port,
},
out => {
type => 'tcp',
host => 'localhost',
port => $server_port,
},
},
);
$proxy->register();
Net::Proxy->mainloop(1);
exit;
}
else {
# wait for the proxy to set up
sleep 1;
# no server
my $client = connect_to_port($proxy_port)
or skip "Couldn't start the client: $!", $tests;
# the client is actually not connected at all
is_closed( $client, 'peer' );
$client->close();
}
}
}
|