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

Fix ASAN issue in ws unit tests #2074

Merged
merged 3 commits into from
Jun 11, 2019
Merged
Changes from 1 commit
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
24 changes: 12 additions & 12 deletions nano/core_test/websocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,42 +37,42 @@ boost::optional<std::string> websocket_test_call (std::string host, std::string
}

boost::optional<std::string> ret;
boost::asio::io_context ioc;
boost::asio::ip::tcp::resolver resolver{ ioc };
boost::beast::websocket::stream<boost::asio::ip::tcp::socket> ws{ ioc };
auto ioc (std::make_shared<boost::asio::io_context> ());
boost::asio::ip::tcp::resolver resolver{ *ioc };
auto ws (std::make_shared<boost::beast::websocket::stream<boost::asio::ip::tcp::socket>> (*ioc));

auto const results = resolver.resolve (host, port);
boost::asio::connect (ws.next_layer (), results.begin (), results.end ());
boost::asio::connect (ws->next_layer (), results.begin (), results.end ());

ws.handshake (host, "/");
ws.text (true);
ws.write (boost::asio::buffer (message_a));
ws->handshake (host, "/");
ws->text (true);
ws->write (boost::asio::buffer (message_a));

if (await_ack)
{
boost::beast::flat_buffer buffer;
ws.read (buffer);
ws->read (buffer);
ack_ready = true;
}

if (await_response)
{
assert (response_deadline > 0s);
auto buffer (std::make_shared<boost::beast::flat_buffer> ());
ws.async_read (*buffer, [&ret, buffer](boost::beast::error_code const & ec, std::size_t const n) {
ws->async_read (*buffer, [&ret, ws, buffer](boost::beast::error_code const & ec, std::size_t const n) {
if (!ec)
{
std::ostringstream res;
res << beast_buffers (buffer->data ());
ret = res.str ();
}
});
ioc.run_one_for (response_deadline);
ioc->run_one_for (response_deadline);
}

if (ws.is_open ())
if (ws->is_open ())
{
ws.async_close (boost::beast::websocket::close_code::normal, [](boost::beast::error_code const & ec) {
ws->async_close (boost::beast::websocket::close_code::normal, [ws](boost::beast::error_code const & ec) {
// A synchronous close usually hangs in tests when the server's io_context stops looping
// An async_close solves this problem
});
Expand Down