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
|
use strict;
use warnings;
no warnings 'once';
use Test::More;
use AnyEvent;
use Message::Passing::Output::Test;
use Message::Passing::Input::Socket::UDP;
use Message::Passing::Output::Socket::UDP;
plan skip_all => "Need Net::Statsd for this test"
unless eval { require Net::Statsd; 1; };
my $t = Message::Passing::Output::Test->new;
my $chain = Message::Passing::Input::Socket::UDP->new(
hostname => "localhost",
port => "52552",
output_to => $t,
);
$Net::Statsd::PORT = 52552;
is $t->message_count, 0;
Net::Statsd::increment('site.logins');
my $cv = AnyEvent->condvar;
my $timer = AnyEvent->timer(after => 0.1, cb => sub { $cv->send });
$cv->recv;
is $t->message_count, 1;
my $out = Message::Passing::Output::Socket::UDP->new(
hostname => "localhost",
port => '52552',
);
$cv = AnyEvent->condvar;
$timer = AnyEvent->timer(after => 0.1, cb => sub { $cv->send });
$cv->recv;
$out->consume("foo:bar");
$cv = AnyEvent->condvar;
$timer = AnyEvent->timer(after => 0.1, cb => sub { $cv->send });
$cv->recv;
is $t->message_count, 2;
is_deeply [$t->messages],
[
'site.logins:1|c',
'foo:bar'
];
done_testing;
|