test_spec_rep.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 #include <stdlib.h>
7 
9 
11 
12 void test_fair_queue_in (const char *bind_address_)
13 {
15  TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (rep, bind_address_));
16  size_t len = MAX_SOCKET_STRING;
19 
20  const size_t services = 5;
21  void *reqs[services];
22  for (size_t peer = 0; peer < services; ++peer) {
23  reqs[peer] = test_context_socket (ZMQ_REQ);
24 
26  }
27 
29 
30  s_send_seq (reqs[0], "A", SEQ_END);
31  s_recv_seq (rep, "A", SEQ_END);
32  s_send_seq (rep, "A", SEQ_END);
33  s_recv_seq (reqs[0], "A", SEQ_END);
34 
35  s_send_seq (reqs[0], "A", SEQ_END);
36  s_recv_seq (rep, "A", SEQ_END);
37  s_send_seq (rep, "A", SEQ_END);
38  s_recv_seq (reqs[0], "A", SEQ_END);
39 
40  // TODO: following test fails randomly on some boxes
41 #ifdef SOMEONE_FIXES_THIS
42  // send N requests
43  for (size_t peer = 0; peer < services; ++peer) {
44  char *str = strdup ("A");
45  str[0] += peer;
46  s_send_seq (reqs[peer], str, SEQ_END);
47  free (str);
48  }
49 
50  // handle N requests
51  for (size_t peer = 0; peer < services; ++peer) {
52  char *str = strdup ("A");
53  str[0] += peer;
54  // Test fails here
57  s_recv_seq (reqs[peer], str, SEQ_END);
58  free (str);
59  }
60 #endif
62 
63  for (size_t peer = 0; peer < services; ++peer)
65 }
66 
67 void test_envelope (const char *bind_address_)
68 {
70 
71  TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (rep, bind_address_));
72  size_t len = MAX_SOCKET_STRING;
75 
76  void *dealer = test_context_socket (ZMQ_DEALER);
77 
79 
80  // minimal envelope
81  s_send_seq (dealer, 0, "A", SEQ_END);
82  s_recv_seq (rep, "A", SEQ_END);
83  s_send_seq (rep, "A", SEQ_END);
84  s_recv_seq (dealer, 0, "A", SEQ_END);
85 
86  // big envelope
87  s_send_seq (dealer, "X", "Y", 0, "A", SEQ_END);
88  s_recv_seq (rep, "A", SEQ_END);
89  s_send_seq (rep, "A", SEQ_END);
90  s_recv_seq (dealer, "X", "Y", 0, "A", SEQ_END);
91 
94 }
95 
96 const char bind_inproc[] = "inproc://a";
97 const char bind_tcp[] = "tcp://127.0.0.1:*";
98 
100 {
102 }
103 
105 {
107 }
108 
110 {
112 }
113 
115 {
117 }
118 
119 int main ()
120 {
122 
123  UNITY_BEGIN ();
124 
125  // SHALL receive incoming messages from its peers using a fair-queuing
126  // strategy.
129 
130  // For an incoming message:
131  // SHALL remove and store the address envelope, including the delimiter.
132  // SHALL pass the remaining data frames to its calling application.
133  // SHALL wait for a single reply message from its calling application.
134  // SHALL prepend the address envelope and delimiter.
135  // SHALL deliver this message back to the originating peer.
138 
139  return UNITY_END ();
140 }
UNITY_END
return UNITY_END()
test_fair_queue_in_inproc
void test_fair_queue_in_inproc()
Definition: test_spec_rep.cpp:99
main
int main()
Definition: test_spec_rep.cpp:119
msleep
void msleep(int milliseconds_)
Definition: testutil.cpp:227
RUN_TEST
#define RUN_TEST(func)
Definition: unity_internals.h:615
ZMQ_LAST_ENDPOINT
#define ZMQ_LAST_ENDPOINT
Definition: zmq.h:298
SETUP_TEARDOWN_TESTCONTEXT
#define SETUP_TEARDOWN_TESTCONTEXT
Definition: testutil_unity.hpp:172
rep
void * rep[services]
Definition: test_req_relaxed.cpp:11
services
const size_t services
Definition: test_req_relaxed.cpp:8
test_context_socket_close_zero_linger
void * test_context_socket_close_zero_linger(void *socket_)
Definition: testutil_unity.cpp:215
ZMQ_REQ
#define ZMQ_REQ
Definition: zmq.h:261
zmq_connect
ZMQ_EXPORT int zmq_connect(void *s_, const char *addr_)
Definition: zmq.cpp:307
testutil_unity.hpp
ZMQ_DEALER
#define ZMQ_DEALER
Definition: zmq.h:263
testutil.hpp
update_failure_list.str
str
Definition: update_failure_list.py:41
ZMQ_REP
#define ZMQ_REP
Definition: zmq.h:262
bind_inproc
const char bind_inproc[]
Definition: test_spec_rep.cpp:96
MAX_SOCKET_STRING
#define MAX_SOCKET_STRING
Definition: libzmq/tests/testutil.hpp:35
zmq_bind
ZMQ_EXPORT int zmq_bind(void *s_, const char *addr_)
Definition: zmq.cpp:299
test_fair_queue_in_tcp
void test_fair_queue_in_tcp()
Definition: test_spec_rep.cpp:104
test_context_socket
void * test_context_socket(int type_)
Definition: testutil_unity.cpp:200
SETTLE_TIME
#define SETTLE_TIME
Definition: libzmq/tests/testutil.hpp:31
connect_address
SETUP_TEARDOWN_TESTCONTEXT char connect_address[MAX_SOCKET_STRING]
Definition: test_spec_rep.cpp:10
SEQ_END
const char * SEQ_END
Definition: testutil.cpp:47
len
int len
Definition: php/ext/google/protobuf/map.c:206
s_send_seq
void s_send_seq(void *socket_,...)
Definition: testutil.cpp:135
setup_test_environment
void setup_test_environment(int timeout_seconds_)
Definition: testutil.cpp:201
UNITY_BEGIN
UNITY_BEGIN()
s_recv_seq
void s_recv_seq(void *socket_,...)
Definition: testutil.cpp:158
test_fair_queue_in
void test_fair_queue_in(const char *bind_address_)
Definition: test_spec_rep.cpp:12
bind_tcp
const char bind_tcp[]
Definition: test_spec_rep.cpp:97
test_envelope_inproc
void test_envelope_inproc()
Definition: test_spec_rep.cpp:109
test_envelope
void test_envelope(const char *bind_address_)
Definition: test_spec_rep.cpp:67
test_envelope_tcp
void test_envelope_tcp()
Definition: test_spec_rep.cpp:114
TEST_ASSERT_SUCCESS_ERRNO
#define TEST_ASSERT_SUCCESS_ERRNO(expr)
Definition: proxy_thr.cpp:47
zmq_getsockopt
ZMQ_EXPORT int zmq_getsockopt(void *s_, int option_, void *optval_, size_t *optvallen_)
Definition: zmq.cpp:261


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