mirror of
https://github.com/boostorg/mqtt5.git
synced 2025-07-29 20:17:37 +02:00
fix tests
Summary: related to T12015 Reviewers: ivica Reviewed By: ivica Subscribers: miljen, iljazovic Differential Revision: https://repo.mireo.local/D26693
This commit is contained in:
@ -165,9 +165,9 @@ int main(int argc, char** argv) {
|
||||
.brokers("mqtt.broker", 1883)
|
||||
.run();
|
||||
|
||||
asio::co_spawn(ioc.get_executor(), coroutine(c), asio::detached);
|
||||
co_spawn(ioc.get_executor(), coroutine(c), asio::detached);
|
||||
// or...
|
||||
asio::co_spawn(ioc.get_executor(), nothrow_coroutine(c), asio::detached);
|
||||
co_spawn(ioc.get_executor(), nothrow_coroutine(c), asio::detached);
|
||||
|
||||
ioc.run();
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ int main() {
|
||||
asio::io_context ioc;
|
||||
|
||||
// Spawn the coroutine.
|
||||
asio::co_spawn(ioc.get_executor(), client_publisher(ioc), asio::detached);
|
||||
co_spawn(ioc.get_executor(), client_publisher(ioc), asio::detached);
|
||||
|
||||
// Start the execution.
|
||||
ioc.run();
|
||||
|
@ -71,7 +71,7 @@ int main() {
|
||||
asio::io_context ioc;
|
||||
|
||||
// Spawn the coroutine.
|
||||
asio::co_spawn(ioc, client_receiver(ioc), asio::detached);
|
||||
co_spawn(ioc, client_receiver(ioc), asio::detached);
|
||||
|
||||
// Start the execution.
|
||||
ioc.run();
|
||||
|
@ -54,7 +54,8 @@ inline std::optional<connect_message> decode_connect(
|
||||
x3::big_word >> // keep_alive
|
||||
prop::props_<connect_props>;
|
||||
|
||||
auto vh = type_parse(it, it + remain_length, var_header_);
|
||||
const byte_citer end = it + remain_length;
|
||||
auto vh = type_parse(it, end, var_header_);
|
||||
if (!vh)
|
||||
return std::optional<connect_message>{};
|
||||
|
||||
@ -75,7 +76,7 @@ inline std::optional<connect_message> decode_connect(
|
||||
basic::if_(has_uname)[basic::utf8_] >> // username
|
||||
basic::if_(has_pwd)[basic::utf8_]; // password
|
||||
|
||||
auto pload = type_parse(it, it + remain_length, payload_);
|
||||
auto pload = type_parse(it, end, payload_);
|
||||
if (!pload)
|
||||
return std::optional<connect_message>{};
|
||||
|
||||
|
@ -1,5 +1,8 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/asio/as_tuple.hpp>
|
||||
#include <boost/asio/co_spawn.hpp>
|
||||
#include <boost/asio/detached.hpp>
|
||||
#include <boost/asio/io_context.hpp>
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
#include <boost/asio/post.hpp>
|
||||
@ -8,6 +11,8 @@
|
||||
|
||||
using namespace async_mqtt5;
|
||||
|
||||
constexpr auto use_nothrow_awaitable = asio::as_tuple(asio::use_awaitable);
|
||||
|
||||
namespace async_mqtt5::test {
|
||||
|
||||
enum cancellation_type {
|
||||
@ -153,7 +158,7 @@ void cancel_during_connecting() {
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(cancellation)
|
||||
BOOST_AUTO_TEST_SUITE(cancellation/*, *boost::unit_test::disabled()*/)
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ioc_stop_async_receive) {
|
||||
@ -183,64 +188,45 @@ BOOST_AUTO_TEST_CASE(client_cancel_during_connecting) {
|
||||
cancel_during_connecting<test::client_cancel>();
|
||||
}
|
||||
|
||||
|
||||
// last two ec checks fail, they finish with no_recovery when
|
||||
// you don't call c.cancel()
|
||||
BOOST_AUTO_TEST_CASE(rerunning_the_client) {
|
||||
constexpr int expected_handlers_called = 3;
|
||||
int handlers_called = 0;
|
||||
|
||||
asio::io_context ioc;
|
||||
|
||||
using stream_type = asio::ip::tcp::socket;
|
||||
using client_type = mqtt_client<stream_type>;
|
||||
client_type c(ioc, "");
|
||||
co_spawn(ioc,
|
||||
[&ioc]() -> asio::awaitable<void> {
|
||||
using stream_type = asio::ip::tcp::socket;
|
||||
using client_type = mqtt_client<stream_type>;
|
||||
client_type c(ioc, "");
|
||||
|
||||
c.brokers("mqtt.mireo.local", 1883)
|
||||
.run();
|
||||
c.brokers("mqtt.mireo.local", 1883)
|
||||
.credentials("test-cli", "", "")
|
||||
.run();
|
||||
|
||||
c.async_publish<qos_e::exactly_once>(
|
||||
"cancelled_topic", "cancelled_payload", retain_e::yes, {},
|
||||
[&handlers_called](error_code ec, reason_code rc, pubcomp_props) {
|
||||
BOOST_CHECK_EQUAL(ec, asio::error::operation_aborted);
|
||||
BOOST_CHECK_EQUAL(rc, reason_codes::empty);
|
||||
handlers_called++;
|
||||
}
|
||||
);
|
||||
auto [ec] = co_await c.async_publish<qos_e::at_most_once>(
|
||||
"t", "p", retain_e::yes, publish_props {}, use_nothrow_awaitable
|
||||
);
|
||||
BOOST_CHECK(!ec);
|
||||
|
||||
asio::post(ioc, [&c] { c.cancel(); });
|
||||
c.cancel();
|
||||
|
||||
auto [cec] = co_await c.async_publish<qos_e::at_most_once>(
|
||||
"ct", "cp", retain_e::yes, publish_props {}, use_nothrow_awaitable
|
||||
);
|
||||
BOOST_CHECK(cec == asio::error::operation_aborted);
|
||||
|
||||
asio::steady_timer cancel_timer(c.get_executor());
|
||||
cancel_timer.expires_after(std::chrono::seconds(1));
|
||||
cancel_timer.async_wait(
|
||||
[&](auto) {
|
||||
c.run();
|
||||
|
||||
c.async_publish<qos_e::at_most_once>(
|
||||
"test/mqtt-test", "payload", retain_e::yes, {},
|
||||
[&handlers_called](error_code ec) {
|
||||
BOOST_CHECK(!ec);
|
||||
handlers_called++;
|
||||
}
|
||||
auto [rec] = co_await c.async_publish<qos_e::at_most_once>(
|
||||
"ct", "cp", retain_e::yes, publish_props {}, use_nothrow_awaitable
|
||||
);
|
||||
BOOST_CHECK(!rec);
|
||||
|
||||
c.async_receive([&handlers_called](
|
||||
error_code ec, std::string, std::string, publish_props
|
||||
) {
|
||||
BOOST_CHECK(!ec);
|
||||
handlers_called++;
|
||||
});
|
||||
}
|
||||
co_await c.async_disconnect(use_nothrow_awaitable);
|
||||
co_return;
|
||||
},
|
||||
asio::detached
|
||||
);
|
||||
|
||||
asio::steady_timer timer(c.get_executor());
|
||||
timer.expires_after(std::chrono::seconds(2));
|
||||
timer.async_wait([&](auto) { c.cancel(); });
|
||||
|
||||
ioc.run();
|
||||
BOOST_CHECK_EQUAL(
|
||||
handlers_called, expected_handlers_called
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END();
|
||||
|
@ -133,7 +133,7 @@ BOOST_AUTO_TEST_CASE(websocket_tcp_client_check) {
|
||||
}
|
||||
);
|
||||
|
||||
co_spawn(ioc,
|
||||
co_spawn(ioc,
|
||||
[&]() -> asio::awaitable<void> {
|
||||
co_await sanity_check(c);
|
||||
timer.cancel();
|
||||
|
@ -143,7 +143,7 @@ BOOST_AUTO_TEST_CASE(test_puback) {
|
||||
BOOST_CHECK_EQUAL(*packet_id_, packet_id);
|
||||
|
||||
const auto& [control_byte, remain_length] = *header;
|
||||
auto rv = decoders::decode_puback(remain_length, it);
|
||||
auto rv = decoders::decode_puback(remain_length - sizeof(uint16_t), it);
|
||||
BOOST_CHECK_MESSAGE(rv, "Parsing PUBACK failed.");
|
||||
|
||||
const auto& [reason_code_, pprops] = *rv;
|
||||
|
Reference in New Issue
Block a user