test_shutdown_stress.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MPL-2.0 */
2 
3 #include "testutil.hpp"
4 #include "testutil_unity.hpp"
5 
6 void setUp ()
7 {
8 }
9 
10 void tearDown ()
11 {
12 }
13 
14 #define THREAD_COUNT 100
15 
16 struct thread_data
17 {
19 };
20 
21 extern "C" {
22 static void worker (void *data_)
23 {
24  const thread_data *const tdata = static_cast<const thread_data *> (data_);
25 
26  void *socket = zmq_socket (get_test_context (), ZMQ_SUB);
27 
29 
30  // Start closing the socket while the connecting process is underway.
32 }
33 }
34 
36 {
37  void *threads[THREAD_COUNT];
38 
39  for (int j = 0; j != 10; j++) {
40  // Check the shutdown with many parallel I/O threads.
41  struct thread_data tdata;
44 
45  void *socket = test_context_socket (ZMQ_PUB);
46 
47  bind_loopback_ipv4 (socket, tdata.endpoint, sizeof (tdata.endpoint));
48 
49  for (int i = 0; i != THREAD_COUNT; i++) {
50  threads[i] = zmq_threadstart (&worker, &tdata);
51  }
52 
53  for (int i = 0; i != THREAD_COUNT; i++) {
54  zmq_threadclose (threads[i]);
55  }
56 
58 
60  }
61 }
62 
63 int main ()
64 {
66 
67  UNITY_BEGIN ();
69  return UNITY_END ();
70 }
zmq_ctx_set
ZMQ_EXPORT int zmq_ctx_set(void *context_, int option_, int optval_)
Definition: zmq.cpp:156
data_
StringPiece data_
Definition: bytestream_unittest.cc:60
tearDown
void tearDown()
Definition: test_shutdown_stress.cpp:10
UNITY_END
return UNITY_END()
ZMQ_PUB
#define ZMQ_PUB
Definition: zmq.h:259
zmq_threadstart
ZMQ_EXPORT void * zmq_threadstart(zmq_thread_fn *func_, void *arg_)
Definition: zmq_utils.cpp:54
RUN_TEST
#define RUN_TEST(func)
Definition: unity_internals.h:615
setup_test_context
void setup_test_context()
Definition: testutil_unity.cpp:179
test_shutdown_stress
void test_shutdown_stress()
Definition: test_shutdown_stress.cpp:35
bind_loopback_ipv4
void bind_loopback_ipv4(void *socket_, char *my_endpoint_, size_t len_)
Definition: testutil_unity.cpp:246
teardown_test_context
void teardown_test_context()
Definition: testutil_unity.cpp:189
get_test_context
void * get_test_context()
Definition: testutil_unity.cpp:184
ZMQ_SUB
#define ZMQ_SUB
Definition: zmq.h:260
zmq_connect
ZMQ_EXPORT int zmq_connect(void *s_, const char *addr_)
Definition: zmq.cpp:307
thread_data
Definition: test_proxy.cpp:17
worker
static void worker(void *data_)
Definition: test_shutdown_stress.cpp:22
testutil_unity.hpp
zmq_threadclose
ZMQ_EXPORT void zmq_threadclose(void *thread_)
Definition: zmq_utils.cpp:62
testutil.hpp
MAX_SOCKET_STRING
#define MAX_SOCKET_STRING
Definition: libzmq/tests/testutil.hpp:35
zmq_socket
ZMQ_EXPORT void * zmq_socket(void *, int type_)
Definition: zmq.cpp:230
test_context_socket
void * test_context_socket(int type_)
Definition: testutil_unity.cpp:200
zmq_close
ZMQ_EXPORT int zmq_close(void *s_)
Definition: zmq.cpp:241
i
int i
Definition: gmock-matchers_test.cc:764
THREAD_COUNT
#define THREAD_COUNT
Definition: test_shutdown_stress.cpp:14
setUp
void setUp()
Definition: test_shutdown_stress.cpp:6
setup_test_environment
void setup_test_environment(int timeout_seconds_)
Definition: testutil.cpp:201
UNITY_BEGIN
UNITY_BEGIN()
thread_data::endpoint
char endpoint[MAX_SOCKET_STRING]
Definition: test_shutdown_stress.cpp:18
ZMQ_IO_THREADS
#define ZMQ_IO_THREADS
Definition: zmq.h:181
test_context_socket_close
void * test_context_socket_close(void *socket_)
Definition: testutil_unity.cpp:208
main
int main()
Definition: test_shutdown_stress.cpp:63
TEST_ASSERT_SUCCESS_ERRNO
#define TEST_ASSERT_SUCCESS_ERRNO(expr)
Definition: proxy_thr.cpp:47


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:59