Fix thread destruction in TestPeer and better exception reporting

This commit is contained in:
Vinnie Falco
2013-08-17 07:44:22 -07:00
parent 93f983ad71
commit 2333a38cd7
3 changed files with 34 additions and 0 deletions

View File

@@ -30,6 +30,13 @@ PeerTest::Result::Result (boost::system::error_code const& ec, String const& pre
{ {
} }
PeerTest::Result::Result (std::exception const& e, String const& prefix)
: m_ec (TestPeerBasics::make_error (TestPeerBasics::errc::exceptioned))
, m_message ((prefix == String::empty) ? e.what ()
: prefix + ": " + e.what ())
{
}
bool PeerTest::Result::operator== (Result const& other) const noexcept bool PeerTest::Result::operator== (Result const& other) const noexcept
{ {
return m_ec == other.m_ec; return m_ec == other.m_ec;

View File

@@ -49,6 +49,7 @@ public:
The prefix is prepended to the error message. The prefix is prepended to the error message.
*/ */
explicit Result (boost::system::error_code const& ec, String const& prefix = ""); explicit Result (boost::system::error_code const& ec, String const& prefix = "");
explicit Result (std::exception const& e, String const& prefix = "");
/** Returns true if the error codes match (message is ignored). /** Returns true if the error codes match (message is ignored).
*/ */
@@ -143,30 +144,50 @@ public:
results.server = Result (ec, server.name ()); results.server = Result (ec, server.name ());
} }
catch (std::exception& e)
{
results.server = Result (e, server.name ());
}
catch (...) catch (...)
{ {
results.server = Result (TestPeerBasics::make_error ( results.server = Result (TestPeerBasics::make_error (
TestPeerBasics::errc::exceptioned), server.name ()); TestPeerBasics::errc::exceptioned), server.name ());
} }
} }
catch (std::exception& e)
{
results.server = Result (e, client.name ());
}
catch (...) catch (...)
{ {
results.client = Result (TestPeerBasics::make_error ( results.client = Result (TestPeerBasics::make_error (
TestPeerBasics::errc::exceptioned), client.name ()); TestPeerBasics::errc::exceptioned), client.name ());
} }
} }
catch (std::exception& e)
{
results.server = Result (e, server.name ());
}
catch (...) catch (...)
{ {
results.server = Result (TestPeerBasics::make_error ( results.server = Result (TestPeerBasics::make_error (
TestPeerBasics::errc::exceptioned), server.name ()); TestPeerBasics::errc::exceptioned), server.name ());
} }
} }
catch (std::exception& e)
{
results.server = Result (e, "client");
}
catch (...) catch (...)
{ {
results.client = Result (TestPeerBasics::make_error ( results.client = Result (TestPeerBasics::make_error (
TestPeerBasics::errc::exceptioned), "client"); TestPeerBasics::errc::exceptioned), "client");
} }
} }
catch (std::exception& e)
{
results.server = Result (e, "server");
}
catch (...) catch (...)
{ {
results.server = Result (TestPeerBasics::make_error ( results.server = Result (TestPeerBasics::make_error (

View File

@@ -162,12 +162,18 @@ public:
error () = make_error (errc::timeout); error () = make_error (errc::timeout);
} }
else
{
stopThread ();
}
} }
else else
{ {
// They requested an infinite wait. // They requested an infinite wait.
// //
m_join.wait (); m_join.wait ();
stopThread ();
} }
} }