mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
Improvements to TestPeer and PeerTest classes
This commit is contained in:
@@ -247,3 +247,71 @@ Socket::async_shutdown (BOOST_ASIO_MOVE_ARG(ErrorCall) handler)
|
||||
#endif
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#if 0
|
||||
/* Stream, SyncReadStream, AsyncReadStream, WriteStream, AsyncWriteStream */
|
||||
// Note, missing std::future<> returns
|
||||
class Stream
|
||||
{
|
||||
public:
|
||||
// Stream
|
||||
typedef typename remove_reference<Stream>::type next_layer_type;
|
||||
typedef typename next_layer_type::lowest_layer_type lowest_layer_type;
|
||||
next_layer_type& next_layer()
|
||||
next_layer_type const& next_layer() const
|
||||
lowest_layer_type& lowest_layer()
|
||||
const lowest_layer_type& lowest_layer() const
|
||||
boost::asio::io_service& get_io_service()
|
||||
void close()
|
||||
boost::system::error_code close(boost::system::error_code& ec)
|
||||
|
||||
// SyncWriteStream
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t write_some (const ConstBufferSequence& buffers)
|
||||
template <typename ConstBufferSequence>
|
||||
std::size_t write_some (const ConstBufferSequence& buffers, boost::system::error_code& ec)
|
||||
|
||||
// AsyncWriteStream
|
||||
template <typename ConstBufferSequence, typename WriteHandler>
|
||||
void async_write_some (const ConstBufferSequence& buffers, WriteHandler handler)
|
||||
|
||||
// ReadStream
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t read_some (const MutableBufferSequence& buffers)
|
||||
template <typename MutableBufferSequence>
|
||||
std::size_t read_some (const MutableBufferSequence& buffers, boost::system::error_code& ec)
|
||||
|
||||
// AsyncReadStream
|
||||
template <typename MutableBufferSequence, typename ReadHandler>
|
||||
void async_read_some (const MutableBufferSequence& buffers, ReadHandler handler)
|
||||
};
|
||||
#endif
|
||||
/* members, and the most common base class in which they appear:
|
||||
|
||||
basic_io_object
|
||||
io_service& get_io_service ()
|
||||
|
||||
basic_socket <Protocol> : basic_io_object
|
||||
typedef protocol_type
|
||||
typedef lowest_layer_type
|
||||
lowest_layer_type& lowest_layer ()
|
||||
native_handle () // Socket::native_handle() would return void* and we'd use the templates to do the static_cast
|
||||
cancel ()
|
||||
shutdon (shutdown_type)
|
||||
close ()
|
||||
<various>
|
||||
|
||||
basic_socket_acceptor <Protocol> : basic_io_object
|
||||
typedef protocol_type
|
||||
native_handle ()
|
||||
listen ()
|
||||
accept ()
|
||||
async_accept ()
|
||||
cancel ()
|
||||
close ()
|
||||
|
||||
basic_stream_socket <Protocol> : basic_socket <Protocol>
|
||||
|
||||
*/
|
||||
|
||||
@@ -644,4 +644,15 @@ public:
|
||||
Object* m_impl;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** Dynamically allocate a SocketWrapper.
|
||||
This deduces the template arguments for convenience.
|
||||
*/
|
||||
template <typename Object>
|
||||
SocketWrapper <Object>* newSocketWrapper (Object& object)
|
||||
{
|
||||
return new SocketWrapper <Object> (object);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -76,6 +76,30 @@ protected:
|
||||
typedef value type;
|
||||
};
|
||||
|
||||
// Specialization for boost::asio::buffered_stream
|
||||
template <typename Stream>
|
||||
struct InterfacesOf <boost::asio::buffered_stream <Stream> >
|
||||
{
|
||||
struct value : SocketInterface::Stream { };
|
||||
typedef value type;
|
||||
};
|
||||
|
||||
// Specialization for boost::asio::buffered_read_stream
|
||||
template <typename Stream>
|
||||
struct InterfacesOf <boost::asio::buffered_read_stream <Stream> >
|
||||
{
|
||||
struct value : SocketInterface::Stream { };
|
||||
typedef value type;
|
||||
};
|
||||
|
||||
// Specialization for boost::asio::buffered_write_stream
|
||||
template <typename Stream>
|
||||
struct InterfacesOf <boost::asio::buffered_write_stream <Stream> >
|
||||
{
|
||||
struct value : SocketInterface::Stream { };
|
||||
typedef value type;
|
||||
};
|
||||
|
||||
// Specialization for boost::asio::ssl::stream
|
||||
template <typename Stream>
|
||||
struct InterfacesOf <boost::asio::ssl::stream <Stream> >
|
||||
|
||||
@@ -26,7 +26,7 @@ PeerTest::Result::Result ()
|
||||
PeerTest::Result::Result (boost::system::error_code const& ec, String const& prefix)
|
||||
: m_ec (ec)
|
||||
, m_message ((prefix == String::empty) ? ec.message ()
|
||||
: prefix + " " + ec.message ())
|
||||
: prefix + ": " + ec.message ())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -105,27 +105,25 @@ public:
|
||||
|
||||
/** Test two peers and return the results.
|
||||
*/
|
||||
template <typename Details, typename ServerLogic, typename ClientLogic, class Arg>
|
||||
static Results run (Arg const& arg, int timeoutSeconds = defaultTimeoutSeconds)
|
||||
template <typename Details, typename ClientLogic, typename ServerLogic, typename ClientArg, typename ServerArg>
|
||||
static Results run (ClientArg const& clientArg, ServerArg const& serverArg, int timeoutSeconds = defaultTimeoutSeconds)
|
||||
{
|
||||
Results results;
|
||||
|
||||
if (Process::isRunningUnderDebugger ())
|
||||
timeoutSeconds = -1;
|
||||
|
||||
results.name = Details::getArgName (arg);
|
||||
|
||||
try
|
||||
{
|
||||
TestPeerType <ServerLogic, Details> server (arg);
|
||||
TestPeerType <ServerLogic, Details> server (serverArg);
|
||||
|
||||
results.name << " / " << server.name ();
|
||||
results.name = server.name () + Details::getArgName (serverArg);
|
||||
|
||||
try
|
||||
{
|
||||
TestPeerType <ClientLogic, Details> client (arg);
|
||||
TestPeerType <ClientLogic, Details> client (clientArg);
|
||||
|
||||
results.name << " / " << client.name ();
|
||||
results.name << " / " + client.name () + Details::getArgName (clientArg);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -179,6 +177,12 @@ public:
|
||||
return results;
|
||||
}
|
||||
|
||||
template <typename Details, typename ClientLogic, typename ServerLogic, class Arg>
|
||||
static Results run (Arg const& arg, int timeoutSeconds = defaultTimeoutSeconds)
|
||||
{
|
||||
return run <Details, ClientLogic, ServerLogic, Arg, Arg> (arg, arg, timeoutSeconds);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/** Reports tests of Details for all known asynchronous logic combinations to a UnitTest.
|
||||
@@ -188,7 +192,7 @@ public:
|
||||
int timeoutSeconds = defaultTimeoutSeconds,
|
||||
bool beginTestCase = true)
|
||||
{
|
||||
run <Details, TestPeerLogicAsyncServer, TestPeerLogicAsyncClient>
|
||||
run <Details, TestPeerLogicAsyncClient, TestPeerLogicAsyncServer>
|
||||
(arg, timeoutSeconds).report (test, beginTestCase);
|
||||
}
|
||||
|
||||
@@ -199,13 +203,13 @@ public:
|
||||
int timeoutSeconds = defaultTimeoutSeconds,
|
||||
bool beginTestCase = true)
|
||||
{
|
||||
run <Details, TestPeerLogicSyncServer, TestPeerLogicSyncClient>
|
||||
run <Details, TestPeerLogicSyncClient, TestPeerLogicSyncServer>
|
||||
(arg, timeoutSeconds).report (test, beginTestCase);
|
||||
|
||||
run <Details, TestPeerLogicSyncServer, TestPeerLogicAsyncClient>
|
||||
run <Details, TestPeerLogicAsyncClient, TestPeerLogicSyncServer>
|
||||
(arg, timeoutSeconds).report (test, beginTestCase);
|
||||
|
||||
run <Details, TestPeerLogicAsyncServer, TestPeerLogicSyncClient>
|
||||
run <Details, TestPeerLogicSyncClient, TestPeerLogicAsyncServer>
|
||||
(arg, timeoutSeconds).report (test, beginTestCase);
|
||||
|
||||
report_async <Details> (test, arg, timeoutSeconds, beginTestCase);
|
||||
|
||||
@@ -48,10 +48,10 @@ public:
|
||||
static String getArgName (arg_type arg)
|
||||
{
|
||||
if (arg == protocol_type::v4 ())
|
||||
return "tcpv4";
|
||||
return ".tcpv4";
|
||||
else if (arg == protocol_type::v6 ())
|
||||
return "tcpv6";
|
||||
return "tcp?";
|
||||
return ".tcpv6";
|
||||
return ".tcp?";
|
||||
}
|
||||
|
||||
String name ()
|
||||
|
||||
@@ -135,10 +135,18 @@ void TestPeerLogicAsyncClient::on_shutdown (error_code const& ec)
|
||||
{
|
||||
if (success (error (ec), true))
|
||||
{
|
||||
if (success (socket ().close (error ())))
|
||||
if (socket ().requires_handshake ())
|
||||
{
|
||||
// doing nothing here is intended,
|
||||
// as the calls to success() may set error()
|
||||
socket ().shutdown (Socket::shutdown_both, error ());
|
||||
}
|
||||
|
||||
if (! error ())
|
||||
{
|
||||
if (success (socket ().close (error ())))
|
||||
{
|
||||
// doing nothing here is intended,
|
||||
// as the calls to success() may set error()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,6 +100,11 @@ void TestPeerLogicAsyncServer::on_shutdown (error_code const& ec)
|
||||
{
|
||||
if (success (error (ec), true))
|
||||
{
|
||||
if (socket ().requires_handshake ())
|
||||
{
|
||||
socket ().shutdown (Socket::shutdown_both, error ());
|
||||
}
|
||||
|
||||
if (success (socket ().close (error ())))
|
||||
{
|
||||
// doing nothing here is intended,
|
||||
|
||||
@@ -22,14 +22,6 @@
|
||||
class TestPeerUnitTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
enum
|
||||
{
|
||||
timeoutSeconds = 3
|
||||
};
|
||||
|
||||
TestPeerUnitTests () : UnitTest ("TestPeer", "beast", runManual)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename Details, typename Arg >
|
||||
void testDetails (Arg const& arg = Arg ())
|
||||
@@ -43,6 +35,17 @@ public:
|
||||
testDetails <TcpDetails, TcpDetails::arg_type> (protocol::v4 ());
|
||||
testDetails <TcpDetails, TcpDetails::arg_type> (protocol::v6 ());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
enum
|
||||
{
|
||||
timeoutSeconds = 10
|
||||
};
|
||||
|
||||
TestPeerUnitTests () : UnitTest ("TestPeer", "beast", runManual)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
static TestPeerUnitTests testPeerUnitTests;
|
||||
|
||||
Reference in New Issue
Block a user