File: socket_udp.t

package info (click to toggle)
libmessage-passing-perl 0.117-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 544 kB
  • sloc: perl: 2,742; makefile: 2; sh: 1
file content (57 lines) | stat: -rw-r--r-- 1,173 bytes parent folder | download | duplicates (4)
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;