@@ -246,6 +246,48 @@ void reconnect_stop_on_handshake_failed ()
246
246
}
247
247
#endif
248
248
249
+ #ifdef ZMQ_BUILD_DRAFT_API
250
+ #ifdef ZMQ_HAVE_IPC
251
+ // test stopping reconnect after disconnect
252
+ void reconnect_stop_after_disconnect ()
253
+ {
254
+ // Setup sub socket
255
+ void *sub = test_context_socket (ZMQ_SUB);
256
+ // Monitor all events on sub
257
+ TEST_ASSERT_SUCCESS_ERRNO (
258
+ zmq_socket_monitor (sub, " inproc://monitor-sub" , ZMQ_EVENT_ALL));
259
+ // Create socket for collecting monitor events
260
+ void *sub_mon = test_context_socket (ZMQ_PAIR);
261
+ // Connect so they'll get events
262
+ TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub_mon, " inproc://monitor-sub" ));
263
+ // Set option to stop reconnecting after disconnect
264
+ int stopReconnectAfterDisconnect = ZMQ_RECONNECT_STOP_AFTER_DISCONNECT;
265
+ TEST_ASSERT_SUCCESS_ERRNO (
266
+ zmq_setsockopt (sub, ZMQ_RECONNECT_STOP, &stopReconnectAfterDisconnect,
267
+ sizeof (stopReconnectAfterDisconnect)));
268
+
269
+ // Connect to a dummy that cannot be connected
270
+ TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub, " ipc://@dummy" ));
271
+
272
+ // Confirm that connect failed and reconnect
273
+ expect_monitor_event (sub_mon, ZMQ_EVENT_CLOSED);
274
+ expect_monitor_event (sub_mon, ZMQ_EVENT_CONNECT_RETRIED);
275
+
276
+ // Disconnect the sub socket
277
+ TEST_ASSERT_SUCCESS_ERRNO (zmq_disconnect (sub, " ipc://@dummy" ));
278
+
279
+ // Confirm that connect failed and will not reconnect
280
+ expect_monitor_event (sub_mon, ZMQ_EVENT_CLOSED);
281
+
282
+ // Close sub
283
+ test_context_socket_close_zero_linger (sub);
284
+
285
+ // Close monitor
286
+ test_context_socket_close_zero_linger (sub_mon);
287
+ }
288
+ #endif
289
+ #endif
290
+
249
291
void setUp ()
250
292
{
251
293
setup_test_context ();
@@ -267,6 +309,9 @@ int main (void)
267
309
#ifdef ZMQ_BUILD_DRAFT_API
268
310
RUN_TEST (reconnect_stop_on_refused);
269
311
RUN_TEST (reconnect_stop_on_handshake_failed);
312
+ #ifdef ZMQ_HAVE_IPC
313
+ RUN_TEST (reconnect_stop_after_disconnect);
314
+ #endif
270
315
#endif
271
316
return UNITY_END ();
272
317
}
0 commit comments