Fix connect_timeout request_timeout not work + tsan in RPCServerTestSuite (#790)

Fixes #791
This commit is contained in:
cyan317
2023-07-27 13:35:52 +01:00
committed by GitHub
parent 545886561f
commit 665890d410
4 changed files with 18 additions and 45 deletions

View File

@@ -28,26 +28,18 @@
struct MockAsyncRPCEngine
{
public:
MockAsyncRPCEngine()
{
work_.emplace(ioc_); // make sure ctx does not stop on its own
runner_.emplace([this] { ioc_.run(); });
}
~MockAsyncRPCEngine()
{
work_.reset();
ioc_.stop();
if (runner_->joinable())
runner_->join();
}
template <typename Fn>
bool
post(Fn&& func, std::string const& ip)
post(Fn&& func, [[maybe_unused]] std::string const& ip = "")
{
boost::asio::spawn(ioc_, [handler = std::move(func)](auto yield) mutable { handler(yield); });
using namespace boost::asio;
io_context ioc;
spawn(ioc, [handler = std::forward<Fn>(func), _ = make_work_guard(ioc.get_executor())](auto yield) mutable {
handler(yield);
});
ioc.run();
return true;
}
@@ -62,16 +54,10 @@ public:
MOCK_METHOD(void, notifyUnknownCommand, (), ());
MOCK_METHOD(void, notifyInternalError, (), ());
MOCK_METHOD(RPC::Result, buildResponse, (Web::Context const&), ());
private:
boost::asio::io_context ioc_;
std::optional<boost::asio::io_service::work> work_;
std::optional<std::thread> runner_;
};
struct MockRPCEngine
{
public:
MOCK_METHOD(bool, post, (std::function<void(boost::asio::yield_context)>&&, std::string const&), ());
MOCK_METHOD(void, notifyComplete, (std::string const&, std::chrono::microseconds const&), ());
MOCK_METHOD(void, notifyErrored, (std::string const&), ());