Skip to content

Commit 86141f4

Browse files
committed
tests added for set_subscription/set_unsubscription socket methods
1 parent 7c4fb9d commit 86141f4

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

test/utility.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#define TEST_DOMAIN "testing"
2828
#define TEST_MESSAGE "hello world!"
29+
#define TEST_TOPIC "hello"
2930
#define TEST_HOST "127.0.0.1"
3031
#define TEST_HOST_BAD "127.0.0.42"
3132
#define TEST_PUBLIC_ENDPOINT "tcp://" TEST_HOST ":9000"
@@ -75,4 +76,4 @@ class simple_thread
7576
}
7677
};
7778

78-
#endif
79+
#endif

test/zmq/socket.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,71 @@ BOOST_AUTO_TEST_CASE(socket__pub_sub__grasslands_asynchronous_connect_first__rec
406406
SEND_MESSAGES_UNTIL(publisher, received);
407407
}
408408

409+
// Default receive-all filter is removed. No message received.
410+
BOOST_AUTO_TEST_CASE(socket__pub_sub__grasslands_asynchronous__no_subscription)
411+
{
412+
zmq::context context;
413+
BOOST_REQUIRE(context);
414+
415+
std::promise<bool> received;
416+
417+
simple_thread publisher_thread([&]()
418+
{
419+
zmq::socket publisher(context, role::publisher);
420+
BOOST_REQUIRE(publisher);
421+
BC_REQUIRE_SUCCESS(publisher.bind({ TEST_PUBLIC_ENDPOINT }));
422+
SEND_MESSAGES_UNTIL(publisher, received); //begin sending now, needs own thread.
423+
});
424+
425+
simple_thread subscriber_thread([&]()
426+
{
427+
zmq::socket subscriber(context, role::subscriber);
428+
BOOST_REQUIRE(subscriber);
429+
430+
data_chunk subscribe_all;
431+
BOOST_REQUIRE(subscriber.set_unsubscription(subscribe_all));
432+
433+
BC_REQUIRE_SUCCESS(subscriber.connect({ TEST_PUBLIC_ENDPOINT }));
434+
435+
RECEIVE_FAILURE(subscriber);
436+
received.set_value(true);
437+
});
438+
}
439+
440+
// Default receive-all filter is removed. "hello" filter is added.
441+
BOOST_AUTO_TEST_CASE(socket__pub_sub__grasslands_asynchronous__hello_subscription_only)
442+
{
443+
zmq::context context;
444+
BOOST_REQUIRE(context);
445+
446+
std::promise<bool> received;
447+
448+
simple_thread publisher_thread([&]()
449+
{
450+
zmq::socket publisher(context, role::publisher);
451+
BOOST_REQUIRE(publisher);
452+
BC_REQUIRE_SUCCESS(publisher.bind({ TEST_PUBLIC_ENDPOINT }));
453+
SEND_MESSAGES_UNTIL(publisher, received);
454+
});
455+
456+
simple_thread subscriber_thread([&]()
457+
{
458+
zmq::socket subscriber(context, role::subscriber);
459+
BOOST_REQUIRE(subscriber);
460+
461+
data_chunk subscribe_all;
462+
BOOST_REQUIRE(subscriber.set_unsubscription(subscribe_all));
463+
464+
std::string topic = TEST_TOPIC;
465+
BOOST_REQUIRE(subscriber.set_subscription(to_chunk(topic)));
466+
467+
BC_REQUIRE_SUCCESS(subscriber.connect({ TEST_PUBLIC_ENDPOINT }));
468+
469+
RECEIVE_MESSAGE(subscriber);
470+
received.set_value(true);
471+
});
472+
}
473+
409474
BOOST_AUTO_TEST_CASE(socket__xpub_xsub__grasslands_two_threads__subscribed)
410475
{
411476
zmq::context context;

0 commit comments

Comments
 (0)