Remove Beast dependency from rebind_executor.hpp and async_traits.hpp

Summary:
related to T15243
remove beast as dependancy from async_traits and rebind_executor

run mqtt_features test on websocket-tcp client instead (tcp broker is usually overloaded)

add tests for next_layer/lowest_layer

Reviewers: ivica

Reviewed By: ivica

Subscribers: iljazovic, miljen

Differential Revision: https://repo.mireo.local/D32212
This commit is contained in:
Korina Šimičević
2024-11-19 08:28:45 +01:00
parent f80c189767
commit edb94108b6
5 changed files with 170 additions and 73 deletions

View File

@ -23,6 +23,8 @@
#include <boost/asio/experimental/awaitable_operators.hpp>
#include <boost/beast/websocket/stream.hpp>
#include <async_mqtt5.hpp>
BOOST_AUTO_TEST_SUITE(mqtt_features/*, *boost::unit_test::disabled()*/)
@ -34,9 +36,9 @@ constexpr auto use_nothrow_awaitable = asio::as_tuple(asio::use_awaitable);
constexpr auto test_duration = std::chrono::seconds(5);
using stream_type = asio::ip::tcp::socket;
using stream_type = boost::beast::websocket::stream<asio::ip::tcp::socket>;
constexpr auto broker = "broker.hivemq.com";
constexpr auto broker = "broker.hivemq.com/mqtt";
constexpr auto connect_wait_dur = std::chrono::milliseconds(200);
constexpr auto topic = "async-mqtt5/test";
constexpr auto share_topic = "$share/sharename/async-mqtt5/test";
@ -62,7 +64,7 @@ asio::awaitable<void> test_manual_use_topic_alias() {
auto ex = co_await asio::this_coro::executor;
mqtt_client<stream_type> client(ex);
client.brokers(broker)
client.brokers(broker, 8000)
.connect_property(prop::topic_alias_maximum, uint16_t(10))
.async_run(asio::detached);
@ -94,7 +96,7 @@ asio::awaitable<void> test_subscription_identifiers() {
auto ex = co_await asio::this_coro::executor;
mqtt_client<stream_type> client(ex);
client.brokers(broker)
client.brokers(broker, 8000)
.async_run(asio::detached);
publish_props pprops;
@ -109,7 +111,7 @@ asio::awaitable<void> test_subscription_identifiers() {
sprops[prop::subscription_identifier] = sub_id;
subscribe_options sub_opts = { .no_local = no_local_e::no };
subscribe_topic sub_topic = { share_topic, sub_opts };
subscribe_topic sub_topic = { topic, sub_opts };
auto&& [ec_2, rcs, __] = co_await client.async_subscribe(
sub_topic, sprops, use_nothrow_awaitable
);
@ -135,7 +137,7 @@ asio::awaitable<void> test_shared_subscription() {
auto ex = co_await asio::this_coro::executor;
mqtt_client<stream_type> client(ex);
client.brokers(broker)
client.brokers(broker, 8000)
.async_run(asio::detached);
subscribe_options sub_opts = { .no_local = no_local_e::no };
@ -170,7 +172,7 @@ asio::awaitable<void> test_user_property() {
auto ex = co_await asio::this_coro::executor;
mqtt_client<stream_type> client(ex);
client.brokers(broker)
client.brokers(broker, 8000)
.async_run(asio::detached);
publish_props pprops;

View File

@ -9,11 +9,12 @@
#include <string>
#include <string_view>
#include <type_traits>
#include <boost/asio/async_result.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/ssl/stream.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/system_executor.hpp>
#include <boost/beast/websocket/stream.hpp>
@ -26,8 +27,6 @@
using namespace async_mqtt5;
BOOST_AUTO_TEST_SUITE(traits/*, *boost::unit_test::disabled()*/)
struct good_authenticator {
good_authenticator() = default;
@ -79,7 +78,6 @@ BOOST_STATIC_ASSERT(detail::has_next_layer<tls_layer>);
BOOST_STATIC_ASSERT(detail::has_next_layer<websocket_tcp_layer>);
BOOST_STATIC_ASSERT(detail::has_next_layer<websocket_tls_layer>);
BOOST_STATIC_ASSERT(!detail::has_tls_layer<tcp_layer>);
BOOST_STATIC_ASSERT(detail::has_tls_layer<tls_layer>);
BOOST_STATIC_ASSERT(!detail::has_tls_layer<websocket_tcp_layer>);
@ -90,10 +88,68 @@ BOOST_STATIC_ASSERT(detail::has_tls_handshake<tls_layer>);
BOOST_STATIC_ASSERT(!detail::has_tls_handshake<websocket_tcp_layer>);
BOOST_STATIC_ASSERT(!detail::has_tls_handshake<websocket_tls_layer>);
BOOST_STATIC_ASSERT(!detail::has_ws_handshake<tcp_layer>);
BOOST_STATIC_ASSERT(!detail::has_ws_handshake<tls_layer>);
BOOST_STATIC_ASSERT(detail::has_ws_handshake<websocket_tcp_layer>);
BOOST_STATIC_ASSERT(detail::has_ws_handshake<websocket_tls_layer>);
BOOST_AUTO_TEST_SUITE_END();
BOOST_STATIC_ASSERT(!detail::has_next_layer<tcp_layer>);
BOOST_STATIC_ASSERT(detail::has_next_layer<tls_layer>);
BOOST_STATIC_ASSERT(detail::has_next_layer<websocket_tcp_layer>);
BOOST_STATIC_ASSERT(detail::has_next_layer<websocket_tls_layer>);
BOOST_STATIC_ASSERT(std::is_same_v<detail::next_layer_type<tcp_layer>, tcp_layer>);
BOOST_STATIC_ASSERT(std::is_same_v<detail::next_layer_type<tls_layer>, tcp_layer>);
BOOST_STATIC_ASSERT(std::is_same_v<detail::next_layer_type<websocket_tcp_layer>, tcp_layer>);
BOOST_STATIC_ASSERT(std::is_same_v<detail::next_layer_type<websocket_tls_layer>, tls_layer>);
BOOST_STATIC_ASSERT(std::is_same_v<detail::lowest_layer_type<tcp_layer>, tcp_layer>);
BOOST_STATIC_ASSERT(std::is_same_v<detail::lowest_layer_type<tls_layer>, tcp_layer>);
BOOST_STATIC_ASSERT(std::is_same_v<detail::lowest_layer_type<websocket_tcp_layer>, tcp_layer>);
BOOST_STATIC_ASSERT(std::is_same_v<detail::lowest_layer_type<websocket_tls_layer>, tcp_layer>);
void tcp_layers_test() {
asio::system_executor ex;
tcp_layer layer(ex);
detail::next_layer_type<tcp_layer>& nlayer = detail::next_layer(layer);
BOOST_STATIC_ASSERT(std::is_same_v<boost::remove_cv_ref_t<decltype(nlayer)>, tcp_layer>);
detail::lowest_layer_type<tcp_layer>& llayer = detail::lowest_layer(layer);
BOOST_STATIC_ASSERT(std::is_same_v<boost::remove_cv_ref_t<decltype(llayer)>, tcp_layer>);
}
void tls_layers_test() {
asio::system_executor ex;
asio::ssl::context ctx(asio::ssl::context::tls_client);
tls_layer layer(ex, ctx);
detail::next_layer_type<tls_layer>& nlayer = detail::next_layer(layer);
BOOST_STATIC_ASSERT(std::is_same_v<boost::remove_cv_ref_t<decltype(nlayer)>, tcp_layer>);
detail::lowest_layer_type<tls_layer>& llayer = detail::lowest_layer(layer);
BOOST_STATIC_ASSERT(std::is_same_v<boost::remove_cv_ref_t<decltype(llayer)>, tcp_layer>);
}
void websocket_tcp_layers_test() {
asio::system_executor ex;
websocket_tcp_layer layer(ex);
detail::next_layer_type<websocket_tcp_layer>& nlayer = detail::next_layer(layer);
BOOST_STATIC_ASSERT(std::is_same_v<boost::remove_cv_ref_t<decltype(nlayer)>, tcp_layer>);
detail::lowest_layer_type<websocket_tcp_layer>& llayer = detail::lowest_layer(layer);
BOOST_STATIC_ASSERT(std::is_same_v<boost::remove_cv_ref_t<decltype(llayer)>, tcp_layer>);
}
void websocket_tls_layers_test() {
asio::system_executor ex;
asio::ssl::context ctx(asio::ssl::context::tls_client);
websocket_tls_layer layer(ex, ctx);
detail::next_layer_type<websocket_tls_layer>& nlayer = detail::next_layer(layer);
BOOST_STATIC_ASSERT(std::is_same_v<boost::remove_cv_ref_t<decltype(nlayer)>, tls_layer>);
detail::lowest_layer_type<websocket_tls_layer>& llayer = detail::lowest_layer(layer);
BOOST_STATIC_ASSERT(std::is_same_v<boost::remove_cv_ref_t<decltype(llayer)>, tcp_layer>);
}