diff --git a/test/net/broadcaster.cpp b/test/net/broadcaster.cpp index 279e42482..180fe5a62 100644 --- a/test/net/broadcaster.cpp +++ b/test/net/broadcaster.cpp @@ -47,20 +47,26 @@ BOOST_AUTO_TEST_CASE(broadcaster__subscribe__stop__expected_code) constexpr auto expected_ec = error::invalid_magic; auto result = true; - std::promise promise; + // Subscription will capture message and stop notifications. + std::promise sub_promise; + std::promise ping_promise; + boost::asio::post(strand, [&]() NOEXCEPT { - BOOST_REQUIRE(!instance.subscribe( + sub_promise.set_value(instance.subscribe( [&](const code& ec, const messages::ping::cptr& ping, broadcaster::channel_id id) NOEXCEPT { // Stop notification has nullptr message, zero id, and specified code. result &= is_null(ping); result &= is_zero(id); - promise.set_value(ec); + ping_promise.set_value(ec); return true; }, channel_id)); }); + // Wait on successful subscription. + BOOST_REQUIRE(!sub_promise.get_future().get()); + boost::asio::post(strand, [&]() NOEXCEPT { instance.stop(expected_ec); @@ -68,7 +74,7 @@ BOOST_AUTO_TEST_CASE(broadcaster__subscribe__stop__expected_code) pool.stop(); BOOST_REQUIRE(pool.join()); - BOOST_REQUIRE_EQUAL(promise.get_future().get(), expected_ec); + BOOST_REQUIRE_EQUAL(ping_promise.get_future().get(), expected_ec); BOOST_REQUIRE(result); } @@ -83,16 +89,17 @@ BOOST_AUTO_TEST_CASE(broadcaster__notify__valid_nonced_ping__expected_notificati auto result = true; // Subscription will capture message and stop notifications. - std::promise promise; + std::promise sub_promise; + std::promise ping_promise; boost::asio::post(strand, [&]() NOEXCEPT { - BOOST_REQUIRE(!instance.subscribe( + sub_promise.set_value(instance.subscribe( [&](const code& ec, const messages::ping::cptr& ping, broadcaster::channel_id id) NOEXCEPT { // Handle stop notification (unavoidable test condition). if (!ping) { - promise.set_value(ec); + ping_promise.set_value(ec); return true; } @@ -104,6 +111,9 @@ BOOST_AUTO_TEST_CASE(broadcaster__notify__valid_nonced_ping__expected_notificati }, channel_id)); }); + // Wait on successful subscription. + BOOST_REQUIRE(!sub_promise.get_future().get()); + // Move vs. emplace required on some platforms, possibly due to default constructor. const auto ping = std::make_shared(messages::ping{ expected_nonce }); boost::asio::post(strand, [&]() NOEXCEPT @@ -118,7 +128,7 @@ BOOST_AUTO_TEST_CASE(broadcaster__notify__valid_nonced_ping__expected_notificati pool.stop(); BOOST_REQUIRE(pool.join()); - BOOST_REQUIRE_EQUAL(promise.get_future().get(), expected_ec); + BOOST_REQUIRE_EQUAL(ping_promise.get_future().get(), expected_ec); BOOST_REQUIRE(result); }