Disconnect_op tests, malformed & resending tests in publish and subscribe op

Summary: related to T12015

Reviewers: ivica

Reviewed By: ivica

Subscribers: miljen, iljazovic

Differential Revision: https://repo.mireo.local/D27323
This commit is contained in:
Korina Šimičević
2024-01-12 09:57:43 +01:00
parent b83e1aa519
commit 3629c19ce9
6 changed files with 564 additions and 40 deletions
@@ -58,12 +58,9 @@ inline std::string_view code_to_str(control_code_e code) {
case control_code_e::pingresp: return "PINGRESP";
default: return "NO PACKET";
}
return "UNKNOWN";
}
inline std::string to_readable_packet(
std::string packet, error_code ec = {}, bool incoming = false
) {
inline std::string to_readable_packet(std::string packet) {
auto control_byte = uint8_t(*packet.data());
auto code = extract_code(control_byte);
@@ -72,14 +69,11 @@ inline std::string to_readable_packet(
std::ostringstream stream;
if (incoming)
stream << "-> ";
if (
code == control_code_e::connect || code == control_code_e::connack ||
code == control_code_e::disconnect
) {
stream << code_to_str(code) << (ec ? " ec: " + ec.message() : "");
stream << code_to_str(code);
return stream.str();
}
@@ -95,6 +89,7 @@ inline std::string to_readable_packet(
auto& [topic, packet_id, flags, props, payload] = *publish;
stream << code_to_str(code);
stream << (packet_id ? " " + std::to_string(*packet_id) : "");
stream << "flags: " << flags;
return stream.str();
}
@@ -150,7 +150,14 @@ public:
for (size_t i = 0; i < num_packets; ++i, ++it) {
BOOST_CHECK_EQUAL(it->size(), expected[i].size());
size_t len = std::min(it->size(), expected[i].size());
BOOST_CHECK(!memcmp(it->data(), expected[i].data(), len));
if (memcmp(it->data(), expected[i].data(), len)) {
std::ostringstream stream;
stream << "Packet mismatch! Expected: "
<< to_readable_packet(expected[i])
<< " Received: "
<< to_readable_packet(std::string((const char*)it->data(), len));
log(stream.str());
}
}
}
@@ -18,9 +18,9 @@ template <
typename StreamType,
typename TlsContext = std::monostate
>
class test_service : public detail::client_service<StreamType, TlsContext> {
class test_service : public async_mqtt5::detail::client_service<StreamType, TlsContext> {
using error_code = boost::system::error_code;
using base = detail::client_service<StreamType, TlsContext>;
using base = async_mqtt5::detail::client_service<StreamType, TlsContext>;
asio::any_io_executor _ex;
connack_props _test_props;