mirror of
https://github.com/boostorg/mqtt5.git
synced 2025-07-31 13:07: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)
|
.brokers("mqtt.broker", 1883)
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
asio::co_spawn(ioc.get_executor(), coroutine(c), asio::detached);
|
co_spawn(ioc.get_executor(), coroutine(c), asio::detached);
|
||||||
// or...
|
// or...
|
||||||
asio::co_spawn(ioc.get_executor(), nothrow_coroutine(c), asio::detached);
|
co_spawn(ioc.get_executor(), nothrow_coroutine(c), asio::detached);
|
||||||
|
|
||||||
ioc.run();
|
ioc.run();
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ int main() {
|
|||||||
asio::io_context ioc;
|
asio::io_context ioc;
|
||||||
|
|
||||||
// Spawn the coroutine.
|
// 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.
|
// Start the execution.
|
||||||
ioc.run();
|
ioc.run();
|
||||||
|
@ -71,7 +71,7 @@ int main() {
|
|||||||
asio::io_context ioc;
|
asio::io_context ioc;
|
||||||
|
|
||||||
// Spawn the coroutine.
|
// Spawn the coroutine.
|
||||||
asio::co_spawn(ioc, client_receiver(ioc), asio::detached);
|
co_spawn(ioc, client_receiver(ioc), asio::detached);
|
||||||
|
|
||||||
// Start the execution.
|
// Start the execution.
|
||||||
ioc.run();
|
ioc.run();
|
||||||
|
@ -54,7 +54,8 @@ inline std::optional<connect_message> decode_connect(
|
|||||||
x3::big_word >> // keep_alive
|
x3::big_word >> // keep_alive
|
||||||
prop::props_<connect_props>;
|
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)
|
if (!vh)
|
||||||
return std::optional<connect_message>{};
|
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_uname)[basic::utf8_] >> // username
|
||||||
basic::if_(has_pwd)[basic::utf8_]; // password
|
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)
|
if (!pload)
|
||||||
return std::optional<connect_message>{};
|
return std::optional<connect_message>{};
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
#include <boost/test/unit_test.hpp>
|
#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/io_context.hpp>
|
||||||
#include <boost/asio/steady_timer.hpp>
|
#include <boost/asio/steady_timer.hpp>
|
||||||
#include <boost/asio/post.hpp>
|
#include <boost/asio/post.hpp>
|
||||||
@ -8,6 +11,8 @@
|
|||||||
|
|
||||||
using namespace async_mqtt5;
|
using namespace async_mqtt5;
|
||||||
|
|
||||||
|
constexpr auto use_nothrow_awaitable = asio::as_tuple(asio::use_awaitable);
|
||||||
|
|
||||||
namespace async_mqtt5::test {
|
namespace async_mqtt5::test {
|
||||||
|
|
||||||
enum cancellation_type {
|
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) {
|
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>();
|
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) {
|
BOOST_AUTO_TEST_CASE(rerunning_the_client) {
|
||||||
constexpr int expected_handlers_called = 3;
|
|
||||||
int handlers_called = 0;
|
|
||||||
|
|
||||||
asio::io_context ioc;
|
asio::io_context ioc;
|
||||||
|
|
||||||
|
co_spawn(ioc,
|
||||||
|
[&ioc]() -> asio::awaitable<void> {
|
||||||
using stream_type = asio::ip::tcp::socket;
|
using stream_type = asio::ip::tcp::socket;
|
||||||
using client_type = mqtt_client<stream_type>;
|
using client_type = mqtt_client<stream_type>;
|
||||||
client_type c(ioc, "");
|
client_type c(ioc, "");
|
||||||
|
|
||||||
c.brokers("mqtt.mireo.local", 1883)
|
c.brokers("mqtt.mireo.local", 1883)
|
||||||
|
.credentials("test-cli", "", "")
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
c.async_publish<qos_e::exactly_once>(
|
auto [ec] = co_await c.async_publish<qos_e::at_most_once>(
|
||||||
"cancelled_topic", "cancelled_payload", retain_e::yes, {},
|
"t", "p", retain_e::yes, publish_props {}, use_nothrow_awaitable
|
||||||
[&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++;
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
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.run();
|
||||||
|
|
||||||
c.async_publish<qos_e::at_most_once>(
|
auto [rec] = co_await c.async_publish<qos_e::at_most_once>(
|
||||||
"test/mqtt-test", "payload", retain_e::yes, {},
|
"ct", "cp", retain_e::yes, publish_props {}, use_nothrow_awaitable
|
||||||
[&handlers_called](error_code ec) {
|
|
||||||
BOOST_CHECK(!ec);
|
|
||||||
handlers_called++;
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
BOOST_CHECK(!rec);
|
||||||
|
|
||||||
c.async_receive([&handlers_called](
|
co_await c.async_disconnect(use_nothrow_awaitable);
|
||||||
error_code ec, std::string, std::string, publish_props
|
co_return;
|
||||||
) {
|
},
|
||||||
BOOST_CHECK(!ec);
|
asio::detached
|
||||||
handlers_called++;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
asio::steady_timer timer(c.get_executor());
|
|
||||||
timer.expires_after(std::chrono::seconds(2));
|
|
||||||
timer.async_wait([&](auto) { c.cancel(); });
|
|
||||||
|
|
||||||
ioc.run();
|
ioc.run();
|
||||||
BOOST_CHECK_EQUAL(
|
|
||||||
handlers_called, expected_handlers_called
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END();
|
BOOST_AUTO_TEST_SUITE_END();
|
||||||
|
@ -143,7 +143,7 @@ BOOST_AUTO_TEST_CASE(test_puback) {
|
|||||||
BOOST_CHECK_EQUAL(*packet_id_, packet_id);
|
BOOST_CHECK_EQUAL(*packet_id_, packet_id);
|
||||||
|
|
||||||
const auto& [control_byte, remain_length] = *header;
|
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.");
|
BOOST_CHECK_MESSAGE(rv, "Parsing PUBACK failed.");
|
||||||
|
|
||||||
const auto& [reason_code_, pprops] = *rv;
|
const auto& [reason_code_, pprops] = *rv;
|
||||||
|
Reference in New Issue
Block a user