Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Update 104_ipc.t #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions t/104_ipc.t
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
use strict;
use warnings;
use Test::More;
use Test::SharedFork;
use File::Temp;
use ZMQ::LibZMQ3::LibZMQ2;
use ZMQ::Constants ':v2.1.11', qw(ZMQ_REP ZMQ_REQ);

BEGIN {
use_ok "ZMQ::LibZMQ3::LibZMQ2";
use_ok "ZMQ::Constants", ":v2.1.11", qw(ZMQ_REP ZMQ_REQ);
}
my $path = File::Temp->new(UNLINK => 1)->filename;

# Test ZMQ modules
use_ok "ZMQ::LibZMQ3::LibZMQ2";
use_ok "ZMQ::Constants", ":v2.1.11", qw(ZMQ_REP ZMQ_REQ);

my $path = File::Temp->new(UNLINK => 0);
my $pid = Test::SharedFork->fork();
if ($pid == 0) {
sleep 1; # hmmm, not a good way to do this...
my $pid = fork();
if (not defined $pid) {
die "Could not fork: $!";
} elsif ($pid == 0) {
my $ctxt = zmq_init();
my $child = zmq_socket($ctxt, ZMQ_REQ );
zmq_connect( $child, "ipc://$path" );
zmq_send( $child, "Hello from $$" );
exit 0;
} elsif ($pid) {
} else {
my $ctxt = zmq_init();
my $parent_sock = zmq_socket( $ctxt, ZMQ_REP);
zmq_bind( $parent_sock, "ipc://$path" );
my $msg = zmq_recv( $parent_sock );
my $data = zmq_msg_data($msg);
if (! is $data, "Hello from $pid", "message is the expected message") {
diag "got '$data', expected 'Hello from $pid'";
}
is($data, "Hello from $pid", "message is the expected message");
waitpid $pid, 0;
} else {
die "Could not fork: $!";
}

unlink $path;
Expand Down