mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-20 18:36:00 +00:00
Problem: tests use hard-coded fixed IPC file path
Solution: use wildcards or random directories to avoid races when multiple users are running the same test on the same machine
This commit is contained in:
parent
4147957a5e
commit
f64b697095
@ -44,11 +44,16 @@ void tearDown ()
|
|||||||
|
|
||||||
void test_roundtrip ()
|
void test_roundtrip ()
|
||||||
{
|
{
|
||||||
|
char my_endpoint[256];
|
||||||
|
size_t len = sizeof (my_endpoint);
|
||||||
|
|
||||||
void *sb = test_context_socket (ZMQ_PAIR);
|
void *sb = test_context_socket (ZMQ_PAIR);
|
||||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "ipc:///tmp/test_pair_ipc"));
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "ipc://*"));
|
||||||
|
TEST_ASSERT_SUCCESS_ERRNO (
|
||||||
|
zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, my_endpoint, &len));
|
||||||
|
|
||||||
void *sc = test_context_socket (ZMQ_PAIR);
|
void *sc = test_context_socket (ZMQ_PAIR);
|
||||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, "ipc:///tmp/test_pair_ipc"));
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, my_endpoint));
|
||||||
|
|
||||||
bounce (sb, sc);
|
bounce (sb, sc);
|
||||||
|
|
||||||
|
@ -42,24 +42,27 @@ void tearDown ()
|
|||||||
teardown_test_context ();
|
teardown_test_context ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *SOCKET_ADDR = "ipc:///tmp/test_rebind_ipc";
|
|
||||||
|
|
||||||
void test_rebind_ipc ()
|
void test_rebind_ipc ()
|
||||||
{
|
{
|
||||||
|
char my_endpoint[256];
|
||||||
|
size_t len = sizeof (my_endpoint);
|
||||||
|
|
||||||
void *sb0 = test_context_socket (ZMQ_PUSH);
|
void *sb0 = test_context_socket (ZMQ_PUSH);
|
||||||
void *sb1 = test_context_socket (ZMQ_PUSH);
|
void *sb1 = test_context_socket (ZMQ_PUSH);
|
||||||
|
|
||||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb0, SOCKET_ADDR));
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb0, "ipc://*"));
|
||||||
|
TEST_ASSERT_SUCCESS_ERRNO (
|
||||||
|
zmq_getsockopt (sb0, ZMQ_LAST_ENDPOINT, my_endpoint, &len));
|
||||||
|
|
||||||
void *sc = test_context_socket (ZMQ_PULL);
|
void *sc = test_context_socket (ZMQ_PULL);
|
||||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, SOCKET_ADDR));
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, my_endpoint));
|
||||||
|
|
||||||
send_string_expect_success (sb0, "42", 0);
|
send_string_expect_success (sb0, "42", 0);
|
||||||
recv_string_expect_success (sc, "42", 0);
|
recv_string_expect_success (sc, "42", 0);
|
||||||
|
|
||||||
test_context_socket_close (sb0);
|
test_context_socket_close (sb0);
|
||||||
|
|
||||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb1, SOCKET_ADDR));
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb1, my_endpoint));
|
||||||
|
|
||||||
send_string_expect_success (sb1, "42", 0);
|
send_string_expect_success (sb1, "42", 0);
|
||||||
recv_string_expect_success (sc, "42", 0);
|
recv_string_expect_success (sc, "42", 0);
|
||||||
|
@ -71,11 +71,15 @@ void test_reconnect_ivl_against_pair_socket (const char *my_endpoint_,
|
|||||||
#if !defined(ZMQ_HAVE_WINDOWS) && !defined(ZMQ_HAVE_GNU)
|
#if !defined(ZMQ_HAVE_WINDOWS) && !defined(ZMQ_HAVE_GNU)
|
||||||
void test_reconnect_ivl_ipc (void)
|
void test_reconnect_ivl_ipc (void)
|
||||||
{
|
{
|
||||||
const char *ipc_endpoint = "ipc:///tmp/test_reconnect_ivl";
|
char my_endpoint[256];
|
||||||
void *sb = test_context_socket (ZMQ_PAIR);
|
size_t len = sizeof (my_endpoint);
|
||||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, ipc_endpoint));
|
|
||||||
|
|
||||||
test_reconnect_ivl_against_pair_socket (ipc_endpoint, sb);
|
void *sb = test_context_socket (ZMQ_PAIR);
|
||||||
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "ipc://*"));
|
||||||
|
TEST_ASSERT_SUCCESS_ERRNO (
|
||||||
|
zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, my_endpoint, &len));
|
||||||
|
|
||||||
|
test_reconnect_ivl_against_pair_socket (my_endpoint, sb);
|
||||||
test_context_socket_close (sb);
|
test_context_socket_close (sb);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -237,24 +237,38 @@ void pre_allocate_sock_ipc_int (void *zmq_socket_, const char *path_)
|
|||||||
sizeof (struct sockaddr_un));
|
sizeof (struct sockaddr_un));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char ipc_endpoint[16];
|
||||||
|
|
||||||
void pre_allocate_sock_ipc (void *sb_, char *my_endpoint_)
|
void pre_allocate_sock_ipc (void *sb_, char *my_endpoint_)
|
||||||
{
|
{
|
||||||
pre_allocate_sock_ipc_int (sb_, "/tmp/test_use_fd_ipc");
|
strcpy (ipc_endpoint, "tmpXXXXXX");
|
||||||
strcpy (my_endpoint_, "ipc:///tmp/test_use_fd_ipc");
|
|
||||||
|
#ifdef HAVE_MKDTEMP
|
||||||
|
TEST_ASSERT_TRUE (mkdtemp (ipc_endpoint));
|
||||||
|
strcat (ipc_endpoint, "/ipc");
|
||||||
|
#else
|
||||||
|
int fd = mkstemp (ipc_endpoint);
|
||||||
|
TEST_ASSERT_TRUE (fd != -1);
|
||||||
|
close (fd);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
pre_allocate_sock_ipc_int (sb_, ipc_endpoint);
|
||||||
|
strcpy (my_endpoint_, "ipc://");
|
||||||
|
strcat (my_endpoint_, ipc_endpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_req_rep_ipc ()
|
void test_req_rep_ipc ()
|
||||||
{
|
{
|
||||||
test_req_rep (pre_allocate_sock_ipc);
|
test_req_rep (pre_allocate_sock_ipc);
|
||||||
|
|
||||||
TEST_ASSERT_SUCCESS_ERRNO (unlink ("/tmp/test_use_fd_ipc"));
|
TEST_ASSERT_SUCCESS_ERRNO (unlink (ipc_endpoint));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_pair_ipc ()
|
void test_pair_ipc ()
|
||||||
{
|
{
|
||||||
test_pair (pre_allocate_sock_ipc);
|
test_pair (pre_allocate_sock_ipc);
|
||||||
|
|
||||||
TEST_ASSERT_SUCCESS_ERRNO (unlink ("/tmp/test_use_fd_ipc"));
|
TEST_ASSERT_SUCCESS_ERRNO (unlink (ipc_endpoint));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_client_server_ipc ()
|
void test_client_server_ipc ()
|
||||||
@ -262,7 +276,7 @@ void test_client_server_ipc ()
|
|||||||
#if defined(ZMQ_SERVER) && defined(ZMQ_CLIENT)
|
#if defined(ZMQ_SERVER) && defined(ZMQ_CLIENT)
|
||||||
test_client_server (pre_allocate_sock_ipc);
|
test_client_server (pre_allocate_sock_ipc);
|
||||||
|
|
||||||
TEST_ASSERT_SUCCESS_ERRNO (unlink ("/tmp/test_use_fd_ipc"));
|
TEST_ASSERT_SUCCESS_ERRNO (unlink (ipc_endpoint));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user