File: 18_shutdown.t

package info (click to toggle)
libpoe-component-irc-perl 6.78%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,540 kB
  • sloc: perl: 16,136; sh: 48; makefile: 5
file content (57 lines) | stat: -rw-r--r-- 1,372 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/env perl

use strict;
use warnings FATAL => 'all';
use POE;
use POE::Component::IRC;
use Socket qw(unpack_sockaddr_in);
use Test::More tests => 4;

my $bot = POE::Component::IRC->spawn(Flood => 1);

POE::Session->create(
    package_states => [
        main => [qw(
            _start
            _shutdown
            irc_shutdown
        )],
    ],
);

$poe_kernel->run();

sub _start {
    my ($kernel, $parent_heap) = @_[KERNEL, HEAP];

    $bot->yield(register => 'all');
    # we're testing if pocoirc correctly copes with a session immediately
    # dying after sending a 'shutdown' event
    POE::Session->create(
        inline_states => {
            _start => sub {
                $parent_heap->{sub_id} = $_[SESSION]->ID();
                pass('Subsession started');
                $bot->yield('shutdown');
            },
            _stop => sub {
                pass('Subsession stopped');
            }
        },
    );
    $kernel->delay(_shutdown => 60, 'Timed out');
}

sub irc_shutdown {
    my ($heap, $killer_id) = @_[HEAP, ARG0];
    pass('IRC component shut down');
    is($killer_id, $heap->{sub_id}, 'Killer session id matches');
    $poe_kernel->yield('_shutdown');
}

sub _shutdown {
    my ($kernel, $error) = @_[KERNEL, ARG0];
    fail($error) if defined $error;
    $kernel->alarm_remove_all();
    $bot->yield('shutdown');
}