Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System test broker with crash #754

Merged
merged 4 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 42 additions & 100 deletions include/mqtt/endpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4796,8 +4796,8 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
}

bool handle_close_or_error(error_code ec) {
if (!ec) return false;
if (connected_) {
if (!ec) return false;
connected_ = false;
mqtt_connected_ = false;
{
Expand All @@ -4814,6 +4814,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
}
disconnect_requested_ = false;
connect_requested_ = false;
if (!ec) ec = boost::system::errc::make_error_code(boost::system::errc::not_connected);
clean_sub_unsub_inflight_on_error(ec);
return true;
}
Expand Down Expand Up @@ -5225,22 +5226,11 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
call_protocol_error_handlers();
return;
}
socket_->post(
[
self = force_move(self),
session_life_keeper = force_move(session_life_keeper),
buf = force_move(buf),
size,
handler = force_move(handler)
]
() mutable {
handler(
buf.substr(0, size),
buf.substr(size),
force_move(session_life_keeper),
force_move(self)
);
}
handler(
buf.substr(0, size),
buf.substr(size),
force_move(session_life_keeper),
force_move(self)
);
}
}
Expand Down Expand Up @@ -5285,27 +5275,17 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
);
}
else {
socket_->post(
[
self = force_move(self),
session_life_keeper = force_move(session_life_keeper),
buf = force_move(buf),
handler = force_move(handler)
]
() mutable {
auto packet_id =
make_packet_id<Bytes>::apply(
buf.data(),
std::next(buf.data(), boost::numeric_cast<buffer::difference_type>(Bytes))
);
buf.remove_prefix(Bytes);
handler(
packet_id,
force_move(buf),
force_move(session_life_keeper),
force_move(self)
);
}
auto packet_id =
make_packet_id<Bytes>::apply(
buf.data(),
std::next(buf.data(), boost::numeric_cast<buffer::difference_type>(Bytes))
);
buf.remove_prefix(Bytes);
handler(
packet_id,
force_move(buf),
force_move(session_life_keeper),
force_move(self)
);
}
}
Expand Down Expand Up @@ -5409,26 +5389,13 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
);
}
else {
socket_->post(
[
session_life_keeper = force_move(session_life_keeper),
handler = force_move(handler),
buf = force_move(buf),
size,
multiplier,
proc = force_move(proc),
self = force_move(self)
]
() mutable {
proc(
force_move(session_life_keeper),
force_move(buf),
force_move(handler),
size,
multiplier,
force_move(self)
);
}
proc(
force_move(session_life_keeper),
force_move(buf),
force_move(handler),
size,
multiplier,
force_move(self)
);
}
}
Expand Down Expand Up @@ -5585,25 +5552,13 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
);
}
else {
socket_->post(
[
this,
self = force_move(self),
session_life_keeper = force_move(session_life_keeper),
buf = force_move(buf),
handler = force_move(handler),
property_length
]
() mutable {
process_property_id(
force_move(session_life_keeper),
force_move(buf),
property_length,
v5::properties(),
force_move(handler),
force_move(self)
);
}
process_property_id(
force_move(session_life_keeper),
force_move(buf),
property_length,
v5::properties(),
force_move(handler),
force_move(self)
);
}
},
Expand Down Expand Up @@ -5654,29 +5609,16 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
);
}
else {
socket_->post(
[
this,
self = force_move(self),
session_life_keeper = force_move(session_life_keeper),
buf = force_move(buf),
props = force_move(props),
handler = force_move(handler),
property_length_rest
]
() mutable {
auto id = static_cast<v5::property::id>(buf.front());
buf.remove_prefix(1);
process_property_body(
force_move(session_life_keeper),
force_move(buf),
id,
property_length_rest - 1,
force_move(props),
force_move(handler),
force_move(self)
);
}
auto id = static_cast<v5::property::id>(buf.front());
buf.remove_prefix(1);
process_property_body(
force_move(session_life_keeper),
force_move(buf),
id,
property_length_rest - 1,
force_move(props),
force_move(handler),
force_move(self)
);
}
}
Expand Down
1 change: 1 addition & 0 deletions test/system/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ ENDIF ()
IF (MQTT_TEST_7)
LIST (APPEND check_PROGRAMS
st_async_pubsub_2.cpp
st_issue_749.cpp
st_broker_offline_message.cpp
st_remaining_length.cpp
st_utf8string_validate.cpp
Expand Down
86 changes: 86 additions & 0 deletions test/system/st_issue_749.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright Takatoshi Kondo 2020
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#include "../common/test_main.hpp"
#include "combi_test.hpp"
#include "checker.hpp"
#include "test_util.hpp"
#include "../common/global_fixture.hpp"

BOOST_AUTO_TEST_SUITE(st_issue_749)

using namespace MQTT_NS::literals;

BOOST_AUTO_TEST_CASE( broker_assertion_fail ) {

boost::asio::io_context iocb;
MQTT_NS::broker::broker_t b(iocb);
MQTT_NS::optional<test_server_no_tls> s;

std::promise<void> p;
auto f = p.get_future();
std::thread th(
[&] {
s.emplace(iocb, b);
p.set_value();
iocb.run();
}
);
f.wait();

auto finish =
[&] {
as::post(
iocb,
[&] {
s->close();
}
);
};

std::vector<std::shared_ptr<std::thread>> client_th;

std::size_t num_clients = 10;

auto client_thread_func =
[] {
boost::asio::io_context ioc;

int publish_count = 100;

auto c1 = MQTT_NS::make_client(ioc, broker_url, broker_notls_port);
c1->set_clean_session(true);
c1->set_client_id("cid1");

c1->set_connack_handler(
[&c1, &publish_count]
(bool /*sp*/, MQTT_NS::connect_return_code /*connack_return_code*/) {
std::cout << "Publish: " << publish_count << std::endl;
for (std::size_t i = 0; i != 100; ++i) {
c1->publish("topic1", "topic1_contents1", MQTT_NS::qos::at_most_once);
}
c1->disconnect();
return true;
}
);

c1->connect();
ioc.run();
std::cout << "finished" << std::endl;
};

for (unsigned int i = 0; i != num_clients; ++i) {
client_th.push_back(std::make_shared<std::thread>(client_thread_func));
}

for(auto& th: client_th) {
th->join();
}
finish();
th.join();
}

BOOST_AUTO_TEST_SUITE_END()