test_shutdown_stress_tipc.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
  3. This file is part of libzmq, the ZeroMQ core engine in C++.
  4. libzmq is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU Lesser General Public License (LGPL) as published
  6. by the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. As a special exception, the Contributors give you permission to link
  9. this library with independent modules to produce an executable,
  10. regardless of the license terms of these independent modules, and to
  11. copy and distribute the resulting executable under terms of your choice,
  12. provided that you also meet, for each linked independent module, the
  13. terms and conditions of the license of that module. An independent
  14. module is a module which is not derived from or based on this library.
  15. If you modify this library, you must extend this exception to your
  16. version of the library.
  17. libzmq is distributed in the hope that it will be useful, but WITHOUT
  18. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  19. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  20. License for more details.
  21. You should have received a copy of the GNU Lesser General Public License
  22. along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. #include "testutil.hpp"
  25. #include "testutil_unity.hpp"
  26. #include <pthread.h>
  27. void setUp ()
  28. {
  29. }
  30. void tearDown ()
  31. {
  32. }
  33. #define THREAD_COUNT 100
  34. extern "C" {
  35. static void *worker (void *ctx)
  36. {
  37. void *s = zmq_socket (ctx, ZMQ_SUB);
  38. TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (s, "tipc://{5560,0}@0.0.0"));
  39. // Start closing the socket while the connecting process is underway.
  40. TEST_ASSERT_SUCCESS_ERRNO (zmq_close (s));
  41. return NULL;
  42. }
  43. }
  44. void test_shutdown_stress_tipc ()
  45. {
  46. void *s1;
  47. int i;
  48. int j;
  49. pthread_t threads[THREAD_COUNT];
  50. for (j = 0; j != 10; j++) {
  51. // Check the shutdown with many parallel I/O threads.
  52. setup_test_context ();
  53. zmq_ctx_set (get_test_context (), ZMQ_IO_THREADS, 7);
  54. s1 = test_context_socket (ZMQ_PUB);
  55. TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (s1, "tipc://{5560,0,0}"));
  56. for (i = 0; i != THREAD_COUNT; i++) {
  57. TEST_ASSERT_SUCCESS_RAW_ERRNO (
  58. pthread_create (&threads[i], NULL, worker, get_test_context ()));
  59. }
  60. for (i = 0; i != THREAD_COUNT; i++) {
  61. TEST_ASSERT_SUCCESS_RAW_ERRNO (pthread_join (threads[i], NULL));
  62. }
  63. test_context_socket_close (s1);
  64. teardown_test_context ();
  65. }
  66. }
  67. int main ()
  68. {
  69. if (!is_tipc_available ()) {
  70. printf ("TIPC environment unavailable, skipping test\n");
  71. return 77;
  72. }
  73. UNITY_BEGIN ();
  74. RUN_TEST (test_shutdown_stress_tipc);
  75. return UNITY_END ();
  76. }