Skip to content

Commit

Permalink
Fix ASAN issue in ws unit tests (#2074)
Browse files Browse the repository at this point in the history
* Fix ASAN issue in ws unit tests

* Capture io context as well

* Revert to using a local for ioctx
  • Loading branch information
cryptocode authored and Russel Waters committed Jun 11, 2019
1 parent c56941a commit 3b75102
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions nano/core_test/websocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,27 @@ 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 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;
Expand All @@ -70,9 +70,9 @@ boost::optional<std::string> websocket_test_call (std::string host, std::string
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

0 comments on commit 3b75102

Please sign in to comment.