|
@@ -62,8 +62,8 @@ public:
|
|
|
TestSocketRequestor(asiodns::DNSService& dnss,
|
|
|
server_common::portconfig::AddressList& store,
|
|
|
uint16_t expect_port) :
|
|
|
- last_token_(0), break_rollback_(false), dnss_(dnss), store_(store),
|
|
|
- expect_port_(expect_port)
|
|
|
+ last_token_(0), break_rollback_(false), break_release_(false),
|
|
|
+ dnss_(dnss), store_(store), expect_port_(expect_port)
|
|
|
{
|
|
|
// Prepare the requestor (us) for the test
|
|
|
server_common::initTestSocketRequestor(this);
|
|
@@ -106,11 +106,23 @@ public:
|
|
|
/// ::1 address is requested.
|
|
|
bool break_rollback_;
|
|
|
|
|
|
+ /// \brief Throw on releaseSocket
|
|
|
+ ///
|
|
|
+ /// If this is set to true, the releaseSocket will throw SocketError.
|
|
|
+ /// Defaults to false.
|
|
|
+ bool break_release_;
|
|
|
+
|
|
|
/// \brief Release a socket
|
|
|
///
|
|
|
/// This only stores the token passed.
|
|
|
/// \param token The socket to release
|
|
|
+ ///
|
|
|
+ /// \throw SocketError in case the break_release_ is set to true. This is
|
|
|
+ /// to test exception handling.
|
|
|
void releaseSocket(const std::string& token) {
|
|
|
+ if (break_release_) {
|
|
|
+ isc_throw(SocketError, "Fatal test socket error");
|
|
|
+ }
|
|
|
released_tokens_.push_back(token);
|
|
|
}
|
|
|
|
|
@@ -119,8 +131,9 @@ public:
|
|
|
/// This creates a new token and fakes a new socket and returns it.
|
|
|
/// The token is stored.
|
|
|
///
|
|
|
- /// In case the address is 192.0.2.2 or if the break_rollback_ is true
|
|
|
- /// and address is ::1, it throws.
|
|
|
+ /// In case the address is 192.0.2.2, it throws SocketAllocateError
|
|
|
+ /// or if the break_rollback_ is true and address is ::1, it throws
|
|
|
+ /// ShareError. If the address is 192.0.2.3, it throws SocketError.
|
|
|
///
|
|
|
/// The tokens produced are in form of protocol:address:port:fd. The fds
|
|
|
/// start at 1 and increase by each successfull call.
|
|
@@ -131,13 +144,18 @@ public:
|
|
|
/// \param mode checked to be DONT_SHARE for now
|
|
|
/// \param name checked to be dummy_app for now
|
|
|
/// \return The token and FD
|
|
|
+ /// \throw SocketAllocateError as described above, to test error handling
|
|
|
+ /// \throw ShareError as described above, to test error handling
|
|
|
/// \throw SocketError as described above, to test error handling
|
|
|
SocketID requestSocket(Protocol protocol, const std::string& address,
|
|
|
uint16_t port, ShareMode mode,
|
|
|
const std::string& name)
|
|
|
{
|
|
|
if (address == "192.0.2.2") {
|
|
|
- isc_throw(SocketError, "This address is not allowed");
|
|
|
+ isc_throw(SocketAllocateError, "This address is not allowed");
|
|
|
+ }
|
|
|
+ if (address == "192.0.2.3") {
|
|
|
+ isc_throw(SocketError, "Fatal test error");
|
|
|
}
|
|
|
if (address == "::1" && break_rollback_) {
|
|
|
// This is valid address, but in case we need to break the
|
|
@@ -145,7 +163,7 @@ public:
|
|
|
//
|
|
|
// We break the second address to see the first one was
|
|
|
// allocated and then returned
|
|
|
- isc_throw(SocketError,
|
|
|
+ isc_throw(ShareError,
|
|
|
"This address is available, but not for you");
|
|
|
}
|
|
|
const std::string proto(protocol == TCP ? "TCP" : "UDP");
|