File: socketfactory-timeout.t

package info (click to toggle)
libpoe-perl 2%3A1.3670-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,996 kB
  • ctags: 1,416
  • sloc: perl: 22,865; makefile: 9
file content (41 lines) | stat: -rw-r--r-- 883 bytes parent folder | download | duplicates (7)
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
#!/usr/bin/env perl

use strict;
use warnings;
use POE qw(Wheel::SocketFactory);
use Test::More tests => 1;

POE::Session->create(
    package_states => [
        main => [qw(_start sock_up sock_down timeout)],
    ],
);

$poe_kernel->run();

sub _start {
    $_[HEAP]->{socket} = POE::Wheel::SocketFactory->new(
        SocketProtocol => 'tcp',
        RemoteAddress  => 'localhost',
        RemotePort     => 0,
        SuccessEvent   => 'sock_up',
        FailureEvent   => 'sock_down',
    );
    $_[KERNEL]->delay('timeout', 5);
}

sub sock_up {
    fail("Successful connection to an unused port?"),
    delete $_[HEAP]->{socket};
    $_[KERNEL]->delay('timeout');
}

sub sock_down {
    pass("Failed to connect as expected");
    delete $_[HEAP]->{socket};
    $_[KERNEL]->delay('timeout');
}

sub timeout {
    fail("Timed out before getting SuccessEvent or FailureEvent");
}