mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-06 17:27:58 +00:00
test: Add test for WsConnection for ping response (#1619)
This commit is contained in:
@@ -75,6 +75,14 @@ TestWsConnection::send(std::string const& message, boost::asio::yield_context yi
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void
|
||||
TestWsConnection::sendPing(boost::beast::websocket::ping_data const& data, boost::asio::yield_context yield)
|
||||
{
|
||||
boost::beast::error_code errorCode;
|
||||
ws_.async_ping(data, yield[errorCode]);
|
||||
[&]() { ASSERT_FALSE(errorCode) << errorCode.message(); }();
|
||||
}
|
||||
|
||||
std::optional<std::string>
|
||||
TestWsConnection::receive(boost::asio::yield_context yield)
|
||||
{
|
||||
@@ -105,6 +113,20 @@ TestWsConnection::headers() const
|
||||
return headers_;
|
||||
}
|
||||
|
||||
void
|
||||
TestWsConnection::setControlFrameCallback(
|
||||
std::function<void(boost::beast::websocket::frame_type, std::string_view)> callback
|
||||
)
|
||||
{
|
||||
ws_.control_callback(std::move(callback));
|
||||
}
|
||||
|
||||
void
|
||||
TestWsConnection::resetControlFrameCallback()
|
||||
{
|
||||
ws_.control_callback();
|
||||
}
|
||||
|
||||
TestWsServer::TestWsServer(asio::io_context& context, std::string const& host) : acceptor_(context)
|
||||
{
|
||||
auto endpoint = asio::ip::tcp::endpoint(boost::asio::ip::make_address(host), 0);
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <boost/asio/spawn.hpp>
|
||||
#include <boost/beast/core/tcp_stream.hpp>
|
||||
#include <boost/beast/websocket/rfc6455.hpp>
|
||||
#include <boost/beast/websocket/stream.hpp>
|
||||
|
||||
#include <expected>
|
||||
@@ -54,6 +55,9 @@ public:
|
||||
std::optional<std::string>
|
||||
send(std::string const& message, boost::asio::yield_context yield);
|
||||
|
||||
void
|
||||
sendPing(boost::beast::websocket::ping_data const& data, boost::asio::yield_context yield);
|
||||
|
||||
// returns nullopt if the connection is closed
|
||||
std::optional<std::string>
|
||||
receive(boost::asio::yield_context yield);
|
||||
@@ -63,6 +67,12 @@ public:
|
||||
|
||||
std::vector<util::requests::HttpHeader> const&
|
||||
headers() const;
|
||||
|
||||
void
|
||||
setControlFrameCallback(std::function<void(boost::beast::websocket::frame_type, std::string_view)> callback);
|
||||
|
||||
void
|
||||
resetControlFrameCallback();
|
||||
};
|
||||
using TestWsConnectionPtr = std::unique_ptr<TestWsConnection>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user