File: 41listen_fail.t

package info (click to toggle)
libnet-proxy-perl 0.12-5
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 304 kB
  • ctags: 66
  • sloc: perl: 777; sh: 84; makefile: 44
file content (39 lines) | stat: -rw-r--r-- 846 bytes parent folder | download | duplicates (6)
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
use Test::More;
use strict;
use warnings;
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 $server = listen_on_port( $proxy_port )
        or skip "Failed to lock port $proxy_port", $tests;

    my $proxy = Net::Proxy->new(
        {   in => {
                type => 'tcp',
                host => 'localhost',
                port => $proxy_port,
            },
            out => {
                type => 'tcp',
                host => 'localhost',
                port => $server_port,
            },
        },
    );

    $proxy->register();
    eval { Net::Proxy->mainloop(); };
    like( $@, qr/^Can't listen on localhost port \d+: /, 'Port in use' );
}