File: test_hwm_pubsub-tcp-fix.patch

package info (click to toggle)
zeromq3 4.3.4-6
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 8,172 kB
  • sloc: cpp: 54,979; ansic: 5,862; makefile: 1,549; sh: 1,138; xml: 203; python: 40
file content (60 lines) | stat: -rw-r--r-- 2,225 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Description: Fix flaky test_hwm_pubsub on riscv64
 The failure has occasionally been seen on other architectures too, but
 shows up very frequently on riscv64, particularly in qemu, so is likely
 timing-dependent.
 .
 Upstream has been investigating the flakiness for years, but don't have
 a perfect fix. The rejected upstream PR this was ported from apparently
 fails on Windows, but we don't care about that.
Author: somdoron <somdoron@gmail.com>
Origin: https://github.com/zeromq/libzmq/pull/3462

--- a/tests/test_hwm_pubsub.cpp
+++ b/tests/test_hwm_pubsub.cpp
@@ -109,13 +109,18 @@ int receive (void *socket_, int *is_term
 int test_blocking (int send_hwm_, int msg_cnt_, const char *endpoint_)
 {
     char pub_endpoint[SOCKET_STRING_LEN];
+    int bufsize = 4096;
 
     // Set up bind socket
     void *pub_socket = test_context_socket (ZMQ_XPUB);
+    TEST_ASSERT_SUCCESS_ERRNO (
+      zmq_setsockopt (pub_socket, ZMQ_SNDBUF, &bufsize, sizeof (int)));
     test_bind (pub_socket, endpoint_, pub_endpoint, sizeof pub_endpoint);
 
     // Set up connect socket
     void *sub_socket = test_context_socket (ZMQ_SUB);
+    TEST_ASSERT_SUCCESS_ERRNO (
+      zmq_setsockopt (pub_socket, ZMQ_RCVBUF, &bufsize, sizeof (int)));
     TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub_socket, pub_endpoint));
 
     //set a hwm on publisher
@@ -140,9 +145,16 @@ int test_blocking (int send_hwm_, int ms
     int recv_count = 0;
     int blocked_count = 0;
     int is_termination = 0;
+
+    zmq_msg_t msg;
+    zmq_msg_init (&msg);
+
     while (send_count < msg_cnt_) {
-        const int rc = zmq_send (pub_socket, NULL, 0, ZMQ_DONTWAIT);
-        if (rc == 0) {
+        zmq_msg_close (&msg);
+        zmq_msg_init_size (&msg, 100);
+
+        const int rc = zmq_msg_send (&msg, pub_socket, ZMQ_DONTWAIT);
+        if (rc >= 0) {
             ++send_count;
         } else if (-1 == rc) {
             // if the PUB socket blocks due to HWM, errno should be EAGAIN:
@@ -152,6 +164,8 @@ int test_blocking (int send_hwm_, int ms
         }
     }
 
+    zmq_msg_close (&msg);
+
     // if send_hwm_ < msg_cnt_, we should block at least once:
     char counts_string[128];
     snprintf (counts_string, sizeof counts_string - 1,