Michal 'vorner' Vaner 13 years ago
parent
commit
1882827541

+ 2 - 0
src/bin/auth/common.cc

@@ -37,3 +37,5 @@ getXfroutSocketPath() {
         }
     }
 }
+
+const char* const AUTH_NAME = "b10-auth";

+ 5 - 0
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:

+ 2 - 2
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

+ 4 - 1
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);

+ 4 - 1
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_);
     }

+ 1 - 0
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
 

+ 17 - 0
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";

+ 23 - 0
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

+ 3 - 2
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.

+ 4 - 1
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);
     }

+ 4 - 10
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);

+ 1 - 1
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.

+ 14 - 6
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);
     }
 }
 

+ 31 - 4
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
 ///

+ 4 - 1
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));

+ 54 - 43
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);
 }
 
 }

+ 19 - 6
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_;
 };
 
 }