BIND 10 master, updated. 18828275414b6a7fa529282e2e53d3ffb2b55082 Merge #1595

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Feb 8 10:45:06 UTC 2012


The branch, master has been updated
       via  18828275414b6a7fa529282e2e53d3ffb2b55082 (commit)
       via  e8580780dacffa82089d030c5b9950eb31c693f6 (commit)
       via  959f4cebed4f1182f4c9f4c3058364e83d553344 (commit)
       via  cb2af9730fdf9f0a9488c1197f29dec90b31c19d (commit)
       via  bf8c9216523617f5834b4acf9f876587995f5078 (commit)
       via  013e14c7d9c84f00510aa8f7a99955aa47c018ad (commit)
       via  33ff861b4cd62e8d2e6063452cc14e980d35bbaf (commit)
       via  b341b3ca37749a29e1f1f286d103298d3c3fa568 (commit)
       via  e3f86da049a7af0ddb0369db2e9db3fa0903d3c5 (commit)
       via  0e7c11723dcde11c0d9d789d072801d383e9ec83 (commit)
       via  9bbda62a5e88e9f1e4c8aeb7924308e37ef65a7c (commit)
      from  90f98423f675dec3fc8335f17bbf761662536cce (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 18828275414b6a7fa529282e2e53d3ffb2b55082
Merge: 90f98423f675dec3fc8335f17bbf761662536cce e8580780dacffa82089d030c5b9950eb31c693f6
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Wed Feb 8 11:24:14 2012 +0100

    Merge #1595

commit e8580780dacffa82089d030c5b9950eb31c693f6
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Wed Feb 8 11:23:47 2012 +0100

    [1595] Language tweaks

commit 959f4cebed4f1182f4c9f4c3058364e83d553344
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Wed Feb 8 11:17:49 2012 +0100

    [1595] Use upper case for constants

commit cb2af9730fdf9f0a9488c1197f29dec90b31c19d
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Tue Feb 7 12:32:09 2012 +0100

    [1595] Docs update

commit bf8c9216523617f5834b4acf9f876587995f5078
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Tue Feb 7 12:15:41 2012 +0100

    [1595] Use constants for the names

commit 013e14c7d9c84f00510aa8f7a99955aa47c018ad
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Tue Feb 7 11:57:49 2012 +0100

    [1595] Use EXPECT_ instead of ASSERT_ if possible

commit 33ff861b4cd62e8d2e6063452cc14e980d35bbaf
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Fri Feb 3 11:04:36 2012 +0100

    [1595] Comments

commit b341b3ca37749a29e1f1f286d103298d3c3fa568
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Fri Feb 3 10:21:13 2012 +0100

    [1595] Remove 'explicit'
    
    The constructor now has multiple parameters, so there's no chance it'd
    get triggered by conversion.

commit e3f86da049a7af0ddb0369db2e9db3fa0903d3c5
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Thu Feb 2 14:19:29 2012 +0100

    [1595] Use share same application
    
    Instead of don't share ‒ we configure the application name, so it should
    work.

commit 0e7c11723dcde11c0d9d789d072801d383e9ec83
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Thu Feb 2 13:48:53 2012 +0100

    [1595] Let portconfig rely on app name

commit 9bbda62a5e88e9f1e4c8aeb7924308e37ef65a7c
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Thu Feb 2 13:19:15 2012 +0100

    [1595] Application name for the socket requestor
    
    It is used when the share name is not explicitly set.

-----------------------------------------------------------------------

Summary of changes:
 src/bin/auth/common.cc                             |    2 +
 src/bin/auth/common.h                              |    5 +
 src/bin/auth/main.cc                               |    4 +-
 src/bin/auth/tests/auth_srv_unittest.cc            |    5 +-
 src/bin/auth/tests/config_unittest.cc              |    5 +-
 src/bin/resolver/Makefile.am                       |    1 +
 .../asiodns/logger.cc => bin/resolver/common.cc}   |   12 +--
 .../asiodns/logger.cc => bin/resolver/common.h}    |   16 ++--
 src/bin/resolver/main.cc                           |    5 +-
 src/bin/resolver/tests/resolver_config_unittest.cc |    5 +-
 src/lib/server_common/portconfig.cc                |   14 +--
 src/lib/server_common/server_common_messages.mes   |    2 +-
 src/lib/server_common/socket_request.cc            |   20 +++-
 src/lib/server_common/socket_request.h             |   35 ++++++-
 src/lib/server_common/tests/portconfig_unittest.cc |    5 +-
 .../server_common/tests/socket_requestor_test.cc   |   97 +++++++++++---------
 src/lib/testutils/socket_request.h                 |   25 ++++-
 17 files changed, 161 insertions(+), 97 deletions(-)
 copy src/{lib/asiodns/logger.cc => bin/resolver/common.cc} (85%)
 copy src/{lib/asiodns/logger.cc => bin/resolver/common.h} (78%)

-----------------------------------------------------------------------
diff --git a/src/bin/auth/common.cc b/src/bin/auth/common.cc
index a7031f3..1602a1a 100644
--- a/src/bin/auth/common.cc
+++ b/src/bin/auth/common.cc
@@ -37,3 +37,5 @@ getXfroutSocketPath() {
         }
     }
 }
+
+const char* const AUTH_NAME = "b10-auth";
diff --git a/src/bin/auth/common.h b/src/bin/auth/common.h
index b913593..cf71214 100644
--- a/src/bin/auth/common.h
+++ b/src/bin/auth/common.h
@@ -38,6 +38,11 @@ public:
 /// The logic should be the same as in b10-xfrout, so they find each other.
 std::string getXfroutSocketPath();
 
+/// \brief The name used when identifieng the process
+///
+/// This is currently b10-auth, but it can be changed easily in one place.
+extern const char* const AUTH_NAME;
+
 #endif // __COMMON_H
 
 // Local Variables:
diff --git a/src/bin/auth/main.cc b/src/bin/auth/main.cc
index 4a425e5..fc2f751 100644
--- a/src/bin/auth/main.cc
+++ b/src/bin/auth/main.cc
@@ -116,7 +116,7 @@ main(int argc, char* argv[]) {
     }
 
     // Initialize logging.  If verbose, we'll use maximum verbosity.
-    isc::log::initLogger("b10-auth",
+    isc::log::initLogger(AUTH_NAME,
                          (verbose ? isc::log::DEBUG : isc::log::INFO),
                          isc::log::MAX_DEBUG_LEVEL, NULL);
 
@@ -154,7 +154,7 @@ main(int argc, char* argv[]) {
         cc_session = new Session(io_service.get_io_service());
         LOG_DEBUG(auth_logger, DBG_AUTH_START, AUTH_CONFIG_CHANNEL_CREATED);
         // Initialize the Socket Requestor
-        isc::server_common::initSocketRequestor(*cc_session);
+        isc::server_common::initSocketRequestor(*cc_session, AUTH_NAME);
 
         // We delay starting listening to new commands/config just before we
         // go into the main loop to avoid confusion due to mixture of
diff --git a/src/bin/auth/tests/auth_srv_unittest.cc b/src/bin/auth/tests/auth_srv_unittest.cc
index 2fccccf..d9c3de6 100644
--- a/src/bin/auth/tests/auth_srv_unittest.cc
+++ b/src/bin/auth/tests/auth_srv_unittest.cc
@@ -71,7 +71,10 @@ protected:
         dnss_(ios_, NULL, NULL, NULL),
         server(true, xfrout),
         rrclass(RRClass::IN()),
-        sock_requestor_(dnss_, address_store_, 53210)
+        // The empty string is expected value of the parameter of
+        // requestSocket, not the app_name (there's no fallback, it checks
+        // the empty string is passed).
+        sock_requestor_(dnss_, address_store_, 53210, "")
     {
         server.setDNSService(dnss_);
         server.setXfrinSession(&notify_session);
diff --git a/src/bin/auth/tests/config_unittest.cc b/src/bin/auth/tests/config_unittest.cc
index 18092c1..973ab31 100644
--- a/src/bin/auth/tests/config_unittest.cc
+++ b/src/bin/auth/tests/config_unittest.cc
@@ -46,7 +46,10 @@ protected:
         dnss_(ios_, NULL, NULL, NULL),
         rrclass(RRClass::IN()),
         server(true, xfrout),
-        sock_requestor_(dnss_, address_store_, 53210)
+        // The empty string is expected value of the parameter of
+        // requestSocket, not the app_name (there's no fallback, it checks
+        // the empty string is passed).
+        sock_requestor_(dnss_, address_store_, 53210, "")
     {
         server.setDNSService(dnss_);
     }
diff --git a/src/bin/resolver/Makefile.am b/src/bin/resolver/Makefile.am
index faa166f..2bb3768 100644
--- a/src/bin/resolver/Makefile.am
+++ b/src/bin/resolver/Makefile.am
@@ -51,6 +51,7 @@ b10_resolver_SOURCES += resolver_log.cc resolver_log.h
 b10_resolver_SOURCES += response_scrubber.cc response_scrubber.h
 b10_resolver_SOURCES += $(top_builddir)/src/bin/auth/common.h
 b10_resolver_SOURCES += main.cc
+b10_resolver_SOURCES += common.cc common.h
 
 nodist_b10_resolver_SOURCES = resolver_messages.cc resolver_messages.h
 
diff --git a/src/bin/resolver/common.cc b/src/bin/resolver/common.cc
new file mode 100644
index 0000000..ad4fc50
--- /dev/null
+++ b/src/bin/resolver/common.cc
@@ -0,0 +1,17 @@
+// Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include "common.h"
+
+const char* const RESOLVER_NAME = "b10-resolver";
diff --git a/src/bin/resolver/common.h b/src/bin/resolver/common.h
new file mode 100644
index 0000000..bcab8ba
--- /dev/null
+++ b/src/bin/resolver/common.h
@@ -0,0 +1,23 @@
+// Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#ifndef RESOLVER_COMMON_H
+#define RESOLVER_COMMON_H
+
+/// \brief The name used to identify the resolver between modules.
+///
+/// It is currently set to b10-resolver.
+extern const char* const RESOLVER_NAME;
+
+#endif
diff --git a/src/bin/resolver/main.cc b/src/bin/resolver/main.cc
index bfcad67..55c0387 100644
--- a/src/bin/resolver/main.cc
+++ b/src/bin/resolver/main.cc
@@ -56,6 +56,7 @@
 #include <log/logger_support.h>
 #include <log/logger_level.h>
 #include "resolver_log.h"
+#include "common.h"
 
 using namespace std;
 using namespace isc::cc;
@@ -121,7 +122,7 @@ main(int argc, char* argv[]) {
 
     // Until proper logging comes along, initialize the logging with the
     // temporary initLogger() code.  If verbose, we'll use maximum verbosity.
-    isc::log::initLogger("b10-resolver",
+    isc::log::initLogger(RESOLVER_NAME,
                          (verbose ? isc::log::DEBUG : isc::log::INFO),
                          isc::log::MAX_DEBUG_LEVEL, NULL);
 
@@ -202,7 +203,7 @@ main(int argc, char* argv[]) {
         LOG_DEBUG(resolver_logger, RESOLVER_DBG_INIT, RESOLVER_SERVICE_CREATED);
 
         cc_session = new Session(io_service.get_io_service());
-        isc::server_common::initSocketRequestor(*cc_session);
+        isc::server_common::initSocketRequestor(*cc_session, RESOLVER_NAME);
 
         // We delay starting listening to new commands/config just before we
         // go into the main loop.   See auth/main.cc for the rationale.
diff --git a/src/bin/resolver/tests/resolver_config_unittest.cc b/src/bin/resolver/tests/resolver_config_unittest.cc
index 1a30941..ea42ba0 100644
--- a/src/bin/resolver/tests/resolver_config_unittest.cc
+++ b/src/bin/resolver/tests/resolver_config_unittest.cc
@@ -85,7 +85,10 @@ protected:
     scoped_ptr<const RequestContext> request;
     ResolverConfig() :
         dnss(ios, NULL, NULL, NULL),
-        sock_requestor_(dnss, address_store_, 53210)
+        // The empty string is expected value of the parameter of
+        // requestSocket, not the app_name (there's no fallback, it checks
+        // the empty string is passed).
+        sock_requestor_(dnss, address_store_, 53210, "")
     {
         server.setDNSService(dnss);
     }
diff --git a/src/lib/server_common/portconfig.cc b/src/lib/server_common/portconfig.cc
index 5c9a7fe..d1e97f3 100644
--- a/src/lib/server_common/portconfig.cc
+++ b/src/lib/server_common/portconfig.cc
@@ -92,17 +92,12 @@ setAddresses(DNSService& service, const AddressList& addresses) {
     current_sockets.clear();
     BOOST_FOREACH(const AddressPair &address, addresses) {
         const int af(IOAddress(address.first).getFamily());
-        // TODO: Support sharing somehow in future.
-
-        // As for now, we hardcode the application name as dummy_app, because:
-        // * we don't have a name available in our interface, which will change
-        //   soon anyway
-        // * we use the DONT_SHARE mode, so the name is irrelevant anyway
+        // We use the application name supplied to the socket requestor on
+        // creation. So we can freely use the SHARE_SAME
         const SocketRequestor::SocketID
             tcp(socketRequestor().requestSocket(SocketRequestor::TCP,
                                                 address.first, address.second,
-                                                SocketRequestor::DONT_SHARE,
-                                                "dummy_app"));
+                                                SocketRequestor::SHARE_SAME));
         current_sockets.push_back(tcp.second);
         if (!test_mode) {
             service.addServerTCPFromFD(tcp.first, af);
@@ -110,8 +105,7 @@ setAddresses(DNSService& service, const AddressList& addresses) {
         const SocketRequestor::SocketID
             udp(socketRequestor().requestSocket(SocketRequestor::UDP,
                                                 address.first, address.second,
-                                                SocketRequestor::DONT_SHARE,
-                                                "dummy_app"));
+                                                SocketRequestor::SHARE_SAME));
         current_sockets.push_back(udp.second);
         if (!test_mode) {
             service.addServerUDPFromFD(udp.first, af);
diff --git a/src/lib/server_common/server_common_messages.mes b/src/lib/server_common/server_common_messages.mes
index 3b3090d..0817928 100644
--- a/src/lib/server_common/server_common_messages.mes
+++ b/src/lib/server_common/server_common_messages.mes
@@ -16,7 +16,7 @@ $NAMESPACE isc::server_common
 
 # \brief Messages for the server_common library
 
-% SOCKETREQUESTOR_CREATED Socket requestor created
+% SOCKETREQUESTOR_CREATED Socket requestor created for application %1
 Debug message.  A socket requesor (client of the socket creator) is created
 for the corresponding application.  Normally this should happen at most
 one time throughout the lifetime of the application.
diff --git a/src/lib/server_common/socket_request.cc b/src/lib/server_common/socket_request.cc
index 546de05..e471ad0 100644
--- a/src/lib/server_common/socket_request.cc
+++ b/src/lib/server_common/socket_request.cc
@@ -264,8 +264,10 @@ getSocketFd(const std::string& token, int sock_pass_fd) {
 // be closed during the lifetime of this class
 class SocketRequestorCCSession : public SocketRequestor {
 public:
-    explicit SocketRequestorCCSession(cc::AbstractSession& session) :
-        session_(session)
+    SocketRequestorCCSession(cc::AbstractSession& session,
+                             const std::string& app_name) :
+        session_(session),
+        app_name_(app_name)
     {
         // We need to filter SIGPIPE to prevent it from happening in
         // getSocketFd() while writing to the UNIX domain socket after the
@@ -278,7 +280,8 @@ public:
             isc_throw(Unexpected, "Failed to filter SIGPIPE: " <<
                       strerror(errno));
         }
-        LOG_DEBUG(logger, DBGLVL_TRACE_BASIC, SOCKETREQUESTOR_CREATED);
+        LOG_DEBUG(logger, DBGLVL_TRACE_BASIC, SOCKETREQUESTOR_CREATED).
+            arg(app_name);
     }
 
     ~SocketRequestorCCSession() {
@@ -293,7 +296,9 @@ public:
     {
         const isc::data::ConstElementPtr request_msg =
             createRequestSocketMessage(protocol, address, port,
-                                       share_mode, share_name);
+                                       share_mode,
+                                       share_name.empty() ? app_name_ :
+                                       share_name);
 
         // Send it to boss
         const int seq = session_.group_sendmsg(request_msg, "Boss");
@@ -377,6 +382,7 @@ private:
     }
 
     cc::AbstractSession& session_;
+    const std::string app_name_;
     std::map<std::string, int> fd_share_sockets_;
 };
 
@@ -392,12 +398,14 @@ socketRequestor() {
 }
 
 void
-initSocketRequestor(cc::AbstractSession& session) {
+initSocketRequestor(cc::AbstractSession& session,
+                    const std::string& app_name)
+{
     if (requestor != NULL) {
         isc_throw(InvalidOperation,
                   "The socket requestor was already initialized");
     } else {
-        requestor = new SocketRequestorCCSession(session);
+        requestor = new SocketRequestorCCSession(session, app_name);
     }
 }
 
diff --git a/src/lib/server_common/socket_request.h b/src/lib/server_common/socket_request.h
index 5708cc1..aac95d1 100644
--- a/src/lib/server_common/socket_request.h
+++ b/src/lib/server_common/socket_request.h
@@ -161,12 +161,31 @@ public:
     /// \param port the port to which the socket should be bound (native endian,
     ///     not network byte order).
     /// \param share_mode how the socket can be shared with other requests.
-    /// This must be one of the defined values of ShareMode.
+    ///     This must be one of the defined values of ShareMode..
     /// \param share_name the name of sharing group, relevant for SHARE_SAME
-    ///     (specified by us or someone else).
+    ///     (specified by us or someone else). If left empty (the default),
+    ///     the app_name parameter of initSocketRequestor is used. If that one
+    ///     is empty as well, it is accepted, but not recommended, as such
+    ///     a non-descriptive name has a high chance of collisions between
+    ///     applications. Note that you should provide a name (by share_name
+    ///     or app_name) even when you set it to DONT_SHARE (for logs and
+    ///     debugging) and you need to provide one with SHARE_SAME (to know
+    ///     what is same) and SHARE_ANY (someone else might want SHARE_SAME,
+    ///     so it would check against this)
     /// \return the socket, as a file descriptor and token representing it on
     ///     the socket creator side.
     ///
+    /// To understand the modes better:
+    /// - If mode is DONT_SHARE, it succeeds if no one else has opened an FD
+    ///   for requested protocol, address and port.
+    /// - If mode is SHARE_SAME, it succeeds if all applications who opened an
+    ///   FD for the requested protocol, address and port provided the same
+    ///   share_name as this one and none of them had mode DONT_SHARE.
+    /// - If mode is SHARE_ANY, it succeeds if no applications who requested
+    ///   the same potocol, address and port provided DONT_SHARE and all the
+    ///   applications who provided SHARE_SAME also provided the same
+    ///   share_name as this process did.
+    ///
     /// \throw InvalidParameter protocol or share_mode is invalid
     /// \throw CCSessionError when we have a problem talking over the CC
     ///     session.
@@ -180,7 +199,7 @@ public:
     virtual SocketID requestSocket(Protocol protocol,
                                    const std::string& address,
                                    uint16_t port, ShareMode share_mode,
-                                   const std::string& share_name) = 0;
+                                   const std::string& share_name = "") = 0;
 
     /// \brief Tell the socket creator we no longer need the socket
     ///
@@ -215,8 +234,16 @@ SocketRequestor& socketRequestor();
 ///
 /// \param session the CC session that'll be used to talk to the
 ///                socket creator.
+/// \param app_name default share name if one is not provided with
+///                 requestSocket. You can leave this as empty string,
+///                 but then you should provide a reasonably descriptive
+///                 name to requestSocket. Empty names work like any others,
+///                 but have a high chance of collisions, so it is recommended
+///                 to avoid them and provide the name of the application
+///                 here.
 /// \throw InvalidOperation when it is called more than once
-void initSocketRequestor(cc::AbstractSession& session);
+void initSocketRequestor(cc::AbstractSession& session,
+                         const std::string& app_name);
 
 /// \brief Initialization for tests
 ///
diff --git a/src/lib/server_common/tests/portconfig_unittest.cc b/src/lib/server_common/tests/portconfig_unittest.cc
index ffeb322..2ea3808 100644
--- a/src/lib/server_common/tests/portconfig_unittest.cc
+++ b/src/lib/server_common/tests/portconfig_unittest.cc
@@ -133,7 +133,10 @@ TEST_F(ParseAddresses, invalid) {
 struct InstallListenAddresses : public ::testing::Test {
     InstallListenAddresses() :
         dnss_(ios_, NULL, NULL, NULL),
-        sock_requestor_(dnss_, store_, 5288)
+        // The empty string is expected parameter of requestSocket,
+        // not app_name - the request does not fall back to this, it
+        // is checked to be the same.
+        sock_requestor_(dnss_, store_, 5288, "")
     {
         valid_.push_back(AddressPair("127.0.0.1", 5288));
         valid_.push_back(AddressPair("::1", 5288));
diff --git a/src/lib/server_common/tests/socket_requestor_test.cc b/src/lib/server_common/tests/socket_requestor_test.cc
index e917e0c..829b6d9 100644
--- a/src/lib/server_common/tests/socket_requestor_test.cc
+++ b/src/lib/server_common/tests/socket_requestor_test.cc
@@ -83,7 +83,7 @@ public:
                                     ElementPtr(new ListElement),
                                     ElementPtr(new ListElement))
     {
-        initSocketRequestor(session);
+        initSocketRequestor(session, "tests");
     }
 
     ~SocketRequestorTest() {
@@ -158,35 +158,46 @@ TEST_F(SocketRequestorTest, testSocketRequestMessages) {
 
     expected_request = createExpectedRequest("192.0.2.1", 12345, "UDP",
                                              "NO", "test");
-    ASSERT_THROW(socketRequestor().requestSocket(SocketRequestor::UDP,
-                                   "192.0.2.1", 12345,
-                                   SocketRequestor::DONT_SHARE,
-                                   "test"),
+    EXPECT_THROW(socketRequestor().requestSocket(SocketRequestor::UDP,
+                                                 "192.0.2.1", 12345,
+                                                 SocketRequestor::DONT_SHARE,
+                                                 "test"),
                  CCSessionError);
     ASSERT_EQ(1, session.getMsgQueue()->size());
-    ASSERT_EQ(*expected_request, *(session.getMsgQueue()->get(0)));
+    EXPECT_EQ(*expected_request, *(session.getMsgQueue()->get(0)));
 
     clearMsgQueue();
     expected_request = createExpectedRequest("192.0.2.2", 1, "TCP",
                                              "ANY", "test2");
-    ASSERT_THROW(socketRequestor().requestSocket(SocketRequestor::TCP,
-                                   "192.0.2.2", 1,
-                                   SocketRequestor::SHARE_ANY,
-                                   "test2"),
+    EXPECT_THROW(socketRequestor().requestSocket(SocketRequestor::TCP,
+                                                 "192.0.2.2", 1,
+                                                 SocketRequestor::SHARE_ANY,
+                                                 "test2"),
                  CCSessionError);
     ASSERT_EQ(1, session.getMsgQueue()->size());
-    ASSERT_EQ(*expected_request, *(session.getMsgQueue()->get(0)));
+    EXPECT_EQ(*expected_request, *(session.getMsgQueue()->get(0)));
 
     clearMsgQueue();
     expected_request = createExpectedRequest("::1", 2, "UDP",
                                              "SAMEAPP", "test3");
-    ASSERT_THROW(socketRequestor().requestSocket(SocketRequestor::UDP,
-                                   "::1", 2,
-                                   SocketRequestor::SHARE_SAME,
-                                   "test3"),
+    EXPECT_THROW(socketRequestor().requestSocket(SocketRequestor::UDP,
+                                                 "::1", 2,
+                                                 SocketRequestor::SHARE_SAME,
+                                                 "test3"),
                  CCSessionError);
     ASSERT_EQ(1, session.getMsgQueue()->size());
-    ASSERT_EQ(*expected_request, *(session.getMsgQueue()->get(0)));
+    EXPECT_EQ(*expected_request, *(session.getMsgQueue()->get(0)));
+
+    // A default share name equal to the app name passed on construction
+    clearMsgQueue();
+    expected_request = createExpectedRequest("::1", 2, "UDP",
+                                             "SAMEAPP", "tests");
+    EXPECT_THROW(socketRequestor().requestSocket(SocketRequestor::UDP,
+                                                 "::1", 2,
+                                   SocketRequestor::SHARE_SAME),
+                 CCSessionError);
+    ASSERT_EQ(1, session.getMsgQueue()->size());
+    EXPECT_EQ(*expected_request, *(session.getMsgQueue()->get(0)));
 }
 
 TEST_F(SocketRequestorTest, invalidParameterForSocketRequest) {
@@ -211,19 +222,19 @@ TEST_F(SocketRequestorTest, testBadRequestAnswers) {
     // Test various scenarios where the requestor gets back bad answers
 
     // Should raise CCSessionError if there is no answer
-    ASSERT_THROW(doRequest(), CCSessionError);
+    EXPECT_THROW(doRequest(), CCSessionError);
 
     // Also if the answer does not match the format
     session.getMessages()->add(createAnswer());
-    ASSERT_THROW(doRequest(), CCSessionError);
+    EXPECT_THROW(doRequest(), CCSessionError);
 
     // Now a 'real' answer, should fail on socket connect (no such file)
     addAnswer("foo", "/does/not/exist");
-    ASSERT_THROW(doRequest(), SocketRequestor::SocketError);
+    EXPECT_THROW(doRequest(), SocketRequestor::SocketError);
 
     // Another failure (domain socket path too long)
     addAnswer("foo", std::string(1000, 'x'));
-    ASSERT_THROW(doRequest(), SocketRequestor::SocketError);
+    EXPECT_THROW(doRequest(), SocketRequestor::SocketError);
 
     // Test values around path boundary
     struct sockaddr_un sock_un;
@@ -236,7 +247,7 @@ TEST_F(SocketRequestorTest, testBadRequestAnswers) {
         doRequest();
         FAIL() << "doRequest did not throw an exception";
     } catch (const SocketRequestor::SocketError& se) {
-        ASSERT_EQ(std::string::npos, std::string(se.what()).find("too long"));
+        EXPECT_EQ(std::string::npos, std::string(se.what()).find("too long"));
     }
 
     const std::string too_long(sizeof(sock_un.sun_path), 'x');
@@ -246,18 +257,18 @@ TEST_F(SocketRequestorTest, testBadRequestAnswers) {
         doRequest();
         FAIL() << "doRequest did not throw an exception";
     } catch (const SocketRequestor::SocketError& se) {
-        ASSERT_NE(std::string::npos, std::string(se.what()).find("too long"));
+        EXPECT_NE(std::string::npos, std::string(se.what()).find("too long"));
     }
 
     // Send back an error response
     // A generic one first
     session.getMessages()->add(createAnswer(1, "error"));
-    ASSERT_THROW(doRequest(), CCSessionError);
+    EXPECT_THROW(doRequest(), CCSessionError);
     // Now some with specific exceptions
     session.getMessages()->add(createAnswer(2, "error"));
-    ASSERT_THROW(doRequest(), SocketRequestor::SocketAllocateError);
+    EXPECT_THROW(doRequest(), SocketRequestor::SocketAllocateError);
     session.getMessages()->add(createAnswer(3, "error"));
-    ASSERT_THROW(doRequest(), SocketRequestor::ShareError);
+    EXPECT_THROW(doRequest(), SocketRequestor::ShareError);
 }
 
 // Helper function to create the release commands as we expect
@@ -286,24 +297,24 @@ TEST_F(SocketRequestorTest, testSocketReleaseMessages) {
     expected_release = createExpectedRelease("foo");
     socketRequestor().releaseSocket("foo");
     ASSERT_EQ(1, session.getMsgQueue()->size());
-    ASSERT_EQ(*expected_release, *(session.getMsgQueue()->get(0)));
+    EXPECT_EQ(*expected_release, *(session.getMsgQueue()->get(0)));
 
     session.getMessages()->add(createAnswer());
     clearMsgQueue();
     expected_release = createExpectedRelease("bar");
     socketRequestor().releaseSocket("bar");
     ASSERT_EQ(1, session.getMsgQueue()->size());
-    ASSERT_EQ(*expected_release, *(session.getMsgQueue()->get(0)));
+    EXPECT_EQ(*expected_release, *(session.getMsgQueue()->get(0)));
 }
 
 TEST_F(SocketRequestorTest, testBadSocketReleaseAnswers) {
     // Should fail if there is no answer at all
-    ASSERT_THROW(socketRequestor().releaseSocket("bar"),
+    EXPECT_THROW(socketRequestor().releaseSocket("bar"),
                  CCSessionError);
 
     // Should also fail if the answer is an error
     session.getMessages()->add(createAnswer(1, "error"));
-    ASSERT_THROW(socketRequestor().releaseSocket("bar"),
+    EXPECT_THROW(socketRequestor().releaseSocket("bar"),
                  SocketRequestor::SocketError);
 }
 
@@ -514,20 +525,20 @@ TEST_F(SocketRequestorTest, testSocketPassing) {
         // 1 should be ok
         addAnswer("foo", ts.getPath());
         socket_id = doRequest();
-        ASSERT_EQ("foo", socket_id.second);
-        ASSERT_EQ(0, close(socket_id.first));
+        EXPECT_EQ("foo", socket_id.second);
+        EXPECT_EQ(0, close(socket_id.first));
 
         // 2 should be ok too
         addAnswer("bar", ts.getPath());
         socket_id = doRequest();
-        ASSERT_EQ("bar", socket_id.second);
-        ASSERT_EQ(0, close(socket_id.first));
+        EXPECT_EQ("bar", socket_id.second);
+        EXPECT_EQ(0, close(socket_id.first));
 
         // 3 should be ok too (reuse earlier token)
         addAnswer("foo", ts.getPath());
         socket_id = doRequest();
-        ASSERT_EQ("foo", socket_id.second);
-        ASSERT_EQ(0, close(socket_id.first));
+        EXPECT_EQ("foo", socket_id.second);
+        EXPECT_EQ(0, close(socket_id.first));
     }
 
     // Create a second socket server, to test that multiple different
@@ -542,35 +553,35 @@ TEST_F(SocketRequestorTest, testSocketPassing) {
         // 1 should be ok
         addAnswer("foo", ts2.getPath());
         socket_id = doRequest();
-        ASSERT_EQ("foo", socket_id.second);
-        ASSERT_EQ(0, close(socket_id.first));
+        EXPECT_EQ("foo", socket_id.second);
+        EXPECT_EQ(0, close(socket_id.first));
     }
 
     if (timo_ok) {
         // Now use first socket again
         addAnswer("foo", ts.getPath());
         socket_id = doRequest();
-        ASSERT_EQ("foo", socket_id.second);
-        ASSERT_EQ(0, close(socket_id.first));
+        EXPECT_EQ("foo", socket_id.second);
+        EXPECT_EQ(0, close(socket_id.first));
 
         // -1 is a "normal" error
         addAnswer("foo", ts.getPath());
-        ASSERT_THROW(doRequest(), SocketRequestor::SocketError);
+        EXPECT_THROW(doRequest(), SocketRequestor::SocketError);
 
         // -2 is an unexpected error.  After this point it's not guaranteed the
         // connection works as intended.
         addAnswer("foo", ts.getPath());
-        ASSERT_THROW(doRequest(), SocketRequestor::SocketError);
+        EXPECT_THROW(doRequest(), SocketRequestor::SocketError);
     }
 
     // Vector is of first socket is now empty, so the socket should be gone
     addAnswer("foo", ts.getPath());
-    ASSERT_THROW(doRequest(), SocketRequestor::SocketError);
+    EXPECT_THROW(doRequest(), SocketRequestor::SocketError);
 
     // Vector is of second socket is now empty too, so the socket should be
     // gone
     addAnswer("foo", ts2.getPath());
-    ASSERT_THROW(doRequest(), SocketRequestor::SocketError);
+    EXPECT_THROW(doRequest(), SocketRequestor::SocketError);
 }
 
 }
diff --git a/src/lib/testutils/socket_request.h b/src/lib/testutils/socket_request.h
index a1e51e2..2c14120 100644
--- a/src/lib/testutils/socket_request.h
+++ b/src/lib/testutils/socket_request.h
@@ -59,11 +59,18 @@ public:
     /// \param expect_port The port which is expected to be requested. If
     ///     the application requests a different port, it is considered
     ///     a failure.
+    /// \param expeted_app The share name for which all the requests should
+    ///     be made. This is not the usual app_name - the requestSocket does
+    ///     not fall back to this value if its share_name is left empty, if
+    ///     you want to check the code relies on the requestor to use the
+    ///     app name, you set this to empty string.
     TestSocketRequestor(asiodns::DNSService& dnss,
                         server_common::portconfig::AddressList& store,
-                        uint16_t expect_port) :
+                        uint16_t expect_port,
+                        const std::string& expected_app) :
         last_token_(0), break_rollback_(false), break_release_(false),
-        dnss_(dnss), store_(store), expect_port_(expect_port)
+        dnss_(dnss), store_(store), expect_port_(expect_port),
+        expected_app_(expected_app)
     {
         // Prepare the requestor (us) for the test
         server_common::initTestSocketRequestor(this);
@@ -141,8 +148,13 @@ public:
     /// \param protocol The protocol to request
     /// \param address to bind to
     /// \param port to bind to
-    /// \param mode checked to be DONT_SHARE for now
-    /// \param name checked to be dummy_app for now
+    /// \param mode checked to be SHARE_SAME for now
+    /// \param name checked to be the same as expected_app parameter of the
+    ///      constructor. Note that this class does not provide the fallback
+    ///      to an app_name if this is empty string. To check the code relies
+    ///      on the fallback (wants to use the app_name instead of providing
+    ///      its own share name), you need to create this class with empty
+    ///      expected_app.
     /// \return The token and FD
     /// \throw SocketAllocateError as described above, to test error handling
     /// \throw ShareError as described above, to test error handling
@@ -169,8 +181,8 @@ public:
         const std::string proto(protocol == TCP ? "TCP" : "UDP");
         const size_t number = ++ last_token_;
         EXPECT_EQ(expect_port_, port);
-        EXPECT_EQ(DONT_SHARE, mode);
-        EXPECT_EQ("dummy_app", name);
+        EXPECT_EQ(SHARE_SAME, mode);
+        EXPECT_EQ(expected_app_, name);
         const std::string token(proto + ":" + address + ":" +
                                 boost::lexical_cast<std::string>(port) + ":" +
                                 boost::lexical_cast<std::string>(number));
@@ -207,6 +219,7 @@ private:
     asiodns::DNSService& dnss_;
     server_common::portconfig::AddressList& store_;
     const uint16_t expect_port_;
+    const std::string expected_app_;
 };
 
 }




More information about the bind10-changes mailing list