Bot-Backbone

 view release on metacpan or  search on metacpan

t/send_policy.t  view on Meta::CPAN

#!/usr/bin/perl
use v5.10;
use Moose;

use lib 't/lib';
#use AnyEvent;
use POE;
use Scalar::Util qw( weaken );
use Test::More tests => 16;

{
    package TestBot;
    use Bot::Backbone;

    use Test::More;

    send_policy use_1_second_interval => (
        MinimumInterval => { interval => 1 },
    );

    send_policy use_1_second_interval_but_discard => (
        MinimumInterval => { interval => 1, discard => 1 },
    );

    send_policy dont_repeat_for_1_second => (
        MinimumRepeatInterval => { 
            interval => 1,
            discard  => 1,
        },
    );

    service chat1 => (
        service     => 'TestChat',
        send_policy => 'use_1_second_interval',
    );

    service chat2 => (
        service     => 'TestChat',
        send_policy => 'use_1_second_interval_but_discard',
    );

    service chat3 => (
        service     => 'TestChat',
        send_policy => 'dont_repeat_for_1_second',
    );

}

my $bot = TestBot->new;
$bot->construct_services;

# For reference during testing below
my $chat1 = $bot->get_service('chat1');
my $chat2 = $bot->get_service('chat2');
my $chat3 = $bot->get_service('chat3');

# TODO Figure out what incantation is required to get this version of the
# test run to work.
#my $w;
#$w = AnyEvent->timer(
#    interval => 0.01,
#    cb       => sub {
#        state $counter = 0;
#
#        $counter++;
#
#        if ($counter < 300) {
#            warn "SENDING $counter\n";



( run in 0.940 second using v1.01-cache-2.11-cpan-39bf76dae61 )