0
0
mirror of https://github.com/zeromq/libzmq.git synced 2024-12-27 07:31:03 +08:00
libzmq/tests/test_shutdown_stress.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

71 lines
1.5 KiB
C++
Raw Normal View History

/* SPDX-License-Identifier: MPL-2.0 */
2010-10-01 16:03:08 +02:00
#include "testutil.hpp"
#include "testutil_unity.hpp"
void setUp ()
{
}
void tearDown ()
{
}
#define THREAD_COUNT 100
2010-10-01 16:03:08 +02:00
struct thread_data
{
char endpoint[MAX_SOCKET_STRING];
};
extern "C" {
static void worker (void *data_)
2010-10-01 16:03:08 +02:00
{
const thread_data *const tdata = static_cast<const thread_data *> (data_);
void *socket = zmq_socket (get_test_context (), ZMQ_SUB);
2010-10-01 16:03:08 +02:00
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (socket, tdata->endpoint));
2010-10-01 16:03:08 +02:00
// Start closing the socket while the connecting process is underway.
TEST_ASSERT_SUCCESS_ERRNO (zmq_close (socket));
}
2010-10-01 16:03:08 +02:00
}
void test_shutdown_stress ()
2010-10-01 16:03:08 +02:00
{
void *threads[THREAD_COUNT];
2010-10-01 16:03:08 +02:00
for (int j = 0; j != 10; j++) {
2010-10-01 16:03:08 +02:00
// Check the shutdown with many parallel I/O threads.
struct thread_data tdata;
setup_test_context ();
zmq_ctx_set (get_test_context (), ZMQ_IO_THREADS, 7);
2010-10-01 16:03:08 +02:00
void *socket = test_context_socket (ZMQ_PUB);
2010-10-01 16:03:08 +02:00
bind_loopback_ipv4 (socket, tdata.endpoint, sizeof (tdata.endpoint));
2010-10-01 16:03:08 +02:00
for (int i = 0; i != THREAD_COUNT; i++) {
threads[i] = zmq_threadstart (&worker, &tdata);
2010-10-01 16:03:08 +02:00
}
for (int i = 0; i != THREAD_COUNT; i++) {
zmq_threadclose (threads[i]);
2010-10-01 16:03:08 +02:00
}
test_context_socket_close (socket);
2010-10-01 16:03:08 +02:00
teardown_test_context ();
2010-10-01 16:03:08 +02:00
}
}
int main ()
{
setup_test_environment (180);
2010-10-01 16:03:08 +02:00
UNITY_BEGIN ();
RUN_TEST (test_shutdown_stress);
return UNITY_END ();
2010-10-01 16:03:08 +02:00
}