mirror of
https://github.com/zeromq/libzmq.git
synced 2025-11-01 21:13:13 +01:00
Problem: tests bind to hardcoded TCP ports
Solution: use ZMQ_LAST_ENDPOINT in most places. This alllows running tests in paralle, and on over-booked shared machines where many of the ports would be already in use. Keep 3 tests with an hardcoded port, as there are some code paths that require it (eg: connect before bind), but list those ports in tests/testutil.hpp as macros so that they do not overlap and still allow parallel runs. These changes were inspired by a patch uploaded to Ubuntu by the package maintainer, Steve Langasek <steve.langasek@ubuntu.com>. Thank you Steve!
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
|
||||
Copyright (c) 2007-2017 Contributors as noted in the AUTHORS file
|
||||
|
||||
This file is part of libzmq, the ZeroMQ core engine in C++.
|
||||
|
||||
@@ -32,29 +32,37 @@
|
||||
int main (void)
|
||||
{
|
||||
setup_test_environment();
|
||||
size_t len = MAX_SOCKET_STRING;
|
||||
char endpoint1[MAX_SOCKET_STRING];
|
||||
char endpoint2[MAX_SOCKET_STRING];
|
||||
void *ctx = zmq_ctx_new ();
|
||||
assert (ctx);
|
||||
|
||||
// First, create an intermediate device
|
||||
void *xpub = zmq_socket (ctx, ZMQ_XPUB);
|
||||
assert (xpub);
|
||||
int rc = zmq_bind (xpub, "tcp://127.0.0.1:5560");
|
||||
int rc = zmq_bind (xpub, "tcp://127.0.0.1:*");
|
||||
assert (rc == 0);
|
||||
rc = zmq_getsockopt (xpub, ZMQ_LAST_ENDPOINT, endpoint1, &len);
|
||||
assert (rc == 0);
|
||||
void *xsub = zmq_socket (ctx, ZMQ_XSUB);
|
||||
assert (xsub);
|
||||
rc = zmq_bind (xsub, "tcp://127.0.0.1:5561");
|
||||
rc = zmq_bind (xsub, "tcp://127.0.0.1:*");
|
||||
assert (rc == 0);
|
||||
len = MAX_SOCKET_STRING;
|
||||
rc = zmq_getsockopt (xsub, ZMQ_LAST_ENDPOINT, endpoint2, &len);
|
||||
assert (rc == 0);
|
||||
|
||||
// Create a publisher
|
||||
void *pub = zmq_socket (ctx, ZMQ_PUB);
|
||||
assert (pub);
|
||||
rc = zmq_connect (pub, "tcp://127.0.0.1:5561");
|
||||
rc = zmq_connect (pub, endpoint2);
|
||||
assert (rc == 0);
|
||||
|
||||
// Create a subscriber
|
||||
void *sub = zmq_socket (ctx, ZMQ_SUB);
|
||||
assert (sub);
|
||||
rc = zmq_connect (sub, "tcp://127.0.0.1:5560");
|
||||
rc = zmq_connect (sub, endpoint1);
|
||||
assert (rc == 0);
|
||||
|
||||
// Subscribe for all messages.
|
||||
|
||||
Reference in New Issue
Block a user