You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2017/05/30 21:03:37 UTC

mesos git commit: Update process tests to set the address of UPIDs.

Repository: mesos
Updated Branches:
  refs/heads/master 4bc477e62 -> cf9ec5de4


Update process tests to set the address of UPIDs.

Some of the remote process tests were using a UPID with a default
0.0.0.0 IP address field. In order to enable subsequent IP address
validation in the libprocess receiver, update these tests to
use a UPID containing the real IP address of the sender.

Review: https://reviews.apache.org/r/58928/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/cf9ec5de
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/cf9ec5de
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/cf9ec5de

Branch: refs/heads/master
Commit: cf9ec5de4c0f26a6fcc7eba7b83c44b52128edd3
Parents: 4bc477e
Author: James Peach <jp...@apache.org>
Authored: Tue May 30 14:00:41 2017 -0700
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Tue May 30 14:03:01 2017 -0700

----------------------------------------------------------------------
 3rdparty/libprocess/src/tests/process_tests.cpp | 20 +++++++++++----
 3rdparty/libprocess/src/tests/test_linkee.cpp   | 26 ++++++++++++++++++++
 2 files changed, 41 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/cf9ec5de/3rdparty/libprocess/src/tests/process_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/process_tests.cpp b/3rdparty/libprocess/src/tests/process_tests.cpp
index 3a27517..a348bdd 100644
--- a/3rdparty/libprocess/src/tests/process_tests.cpp
+++ b/3rdparty/libprocess/src/tests/process_tests.cpp
@@ -1263,9 +1263,12 @@ TEST(ProcessTest, THREADSAFE_Remote)
 
   AWAIT_READY(socket.connect(process.self().address));
 
+  Try<Address> sender = socket.address();
+  ASSERT_SOME(sender);
+
   Message message;
   message.name = "handler";
-  message.from = UPID();
+  message.from = UPID("sender", sender.get());
   message.to = process.self();
 
   const string data = MessageEncoder::encode(&message);
@@ -1296,6 +1299,11 @@ TEST(ProcessTest, THREADSAFE_Http1)
 
   http::Connection connection = connect.get();
 
+  Try<process::network::Address> address = connection.localAddress;
+  ASSERT_SOME(address);
+
+  UPID from("sender", process::network::convert<Address>(address.get()).get());
+
   Future<UPID> pid;
   Future<string> body;
   EXPECT_CALL(process, handler(_, _))
@@ -1305,7 +1313,7 @@ TEST(ProcessTest, THREADSAFE_Http1)
   http::Request request;
   request.method = "POST";
   request.url = url;
-  request.headers["User-Agent"] = "libprocess/";
+  request.headers["User-Agent"] = "libprocess/" + stringify(from);
   request.body = "hello world";
 
   // Send the libprocess request. Note that we will not
@@ -1317,7 +1325,7 @@ TEST(ProcessTest, THREADSAFE_Http1)
   ASSERT_EQ("hello world", body.get());
 
   AWAIT_READY(pid);
-  ASSERT_EQ(UPID(), pid.get());
+  ASSERT_EQ(from, pid.get());
 
   EXPECT_TRUE(response.isPending());
 
@@ -1350,7 +1358,7 @@ TEST_TEMP_DISABLED_ON_WINDOWS(ProcessTest, THREADSAFE_Http2)
   Try<Address> address = socket.address();
   ASSERT_SOME(address);
 
-  UPID from("", address.get());
+  UPID from("", process.self().address.ip, address->port);
 
   ASSERT_SOME(socket.listen(1));
 
@@ -1698,10 +1706,12 @@ TEST(ProcessTest, PercentEncodedURLs)
   EXPECT_CALL(process, handler1(_, _))
     .WillOnce(FutureSatisfy(&handler1));
 
+  UPID from("sender", process.self().address.ip, 99);
+
   http::Request request;
   request.method = "POST";
   request.url = url;
-  request.headers["User-Agent"] = "libprocess/";
+  request.headers["User-Agent"] = "libprocess/" + stringify(from);
 
   // Send the libprocess request. Note that we will not
   // receive a 202 due to the use of the `User-Agent`

http://git-wip-us.apache.org/repos/asf/mesos/blob/cf9ec5de/3rdparty/libprocess/src/tests/test_linkee.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/test_linkee.cpp b/3rdparty/libprocess/src/tests/test_linkee.cpp
index 921d676..77df385 100644
--- a/3rdparty/libprocess/src/tests/test_linkee.cpp
+++ b/3rdparty/libprocess/src/tests/test_linkee.cpp
@@ -127,6 +127,32 @@ int main(int argc, char** argv)
 
   Address address = bind.get();
 
+  // Resolve the hostname if the IP is 0.0.0.0 in case we actually have
+  // a valid external IP address. Note that we need only one IP address,
+  // so that other processes can send and receive and don't get confused
+  // as to whom they are sending to.
+  //
+  // This code is copied from process::initialize(), so it matches
+  // how libprocess proper sets up its listening socket.
+  if (address.ip.isAny()) {
+    char hostname[512];
+
+    if (gethostname(hostname, sizeof(hostname)) < 0) {
+      PLOG(FATAL) << "Failed to get the local hostname";
+    }
+
+    // Lookup an IP address of local hostname, taking the first result.
+    Try<net::IP> ip = net::getIP(hostname, address.ip.family());
+
+    if (ip.isError()) {
+      EXIT(EXIT_FAILURE)
+        << "Failed to obtain the IP address for '" << hostname << "';"
+        << " the DNS service may not be able to resolve it: " << ip.error();
+    }
+
+    address.ip = ip.get();
+  }
+
   // Start listening for incoming sockets.
   Try<Nothing> listen = __s__->listen(LISTEN_BACKLOG);
   if (listen.isError()) {