File: output.t

package info (click to toggle)
libmessage-passing-zeromq-perl 0.010-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 276 kB
  • sloc: perl: 1,621; makefile: 2
file content (42 lines) | stat: -rw-r--r-- 997 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
use strict;
use warnings;
use Test::More;

use AnyEvent;
use JSON qw/ encode_json /;
use Message::Passing::Input::ZeroMQ;
use Message::Passing::Output::Test;
use Message::Passing::Output::ZeroMQ;
use Message::Passing::Filter::Decoder::JSON;

my $pid = fork;
if ($pid){
    # Parent
    my $cv = AnyEvent->condvar;

    my $input = Message::Passing::Input::ZeroMQ->new(
        socket_bind => 'tcp://*:5558',
        output_to => Message::Passing::Filter::Decoder::JSON->new(output_to => Message::Passing::Output::Test->new(
            cb => sub { $cv->send }
        )),
    );
    $cv->recv;

    is $input->output_to->output_to->message_count, 1;
    is_deeply([$input->output_to->output_to->messages], [{foo => 'bar'}]);

    done_testing;
    }
elsif (defined $pid){
    # Child
    my $output = Message::Passing::Output::ZeroMQ->new(
        connect => 'tcp://127.0.0.1:5558',
    );

    $output->consume(encode_json {foo => 'bar'});

    exit;
    }
else {
    die "Failed to fork";
    }