You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2016/12/07 00:25:51 UTC

[2/5] mesos git commit: Fixed HttpServeTests to connect to a non-ANY address.

Fixed HttpServeTests to connect to a non-ANY address.

Connecting to the ANY address (0.0.0.0) is legal in BSD sockets,
but results in an ambiguous connection.  The outgoing connection
could literally be anywhere on the network.

These tests aim to connect to a specific socket on the local
machine, and as such, should supply a valid IP address.
This commit coincidentally fixes these tests on Windows,
which disallows connecting to invalid IP addresses.

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


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

Branch: refs/heads/master
Commit: 1c380d2d70c5def40b210e9699db652f6c0ea1d0
Parents: c18fd73
Author: Joseph Wu <jo...@apache.org>
Authored: Fri Dec 2 15:36:13 2016 -0800
Committer: Joseph Wu <jo...@apache.org>
Committed: Tue Dec 6 16:10:03 2016 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/src/tests/http_tests.cpp | 36 ++++++++++++++++++-----
 1 file changed, 28 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/1c380d2d/3rdparty/libprocess/src/tests/http_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/http_tests.cpp b/3rdparty/libprocess/src/tests/http_tests.cpp
index 7f54257..f4c5dd6 100644
--- a/3rdparty/libprocess/src/tests/http_tests.cpp
+++ b/3rdparty/libprocess/src/tests/http_tests.cpp
@@ -1778,12 +1778,24 @@ TEST_F(HttpServeTest, Pipelining)
   ASSERT_SOME(server->bind(Address::ANY_ANY()));
   ASSERT_SOME(server->listen(1));
 
-  Try<Address> address = server->address();
-  ASSERT_SOME(address);
+  Try<Address> any_address = server->address();
+  ASSERT_SOME(any_address);
+
+  // Connect to the IP from the libprocess library, but use the port
+  // from the `bind` call above. The libprocess IP will always report
+  // a locally bindable IP, meaning it will also work for the server
+  // socket above.
+  //
+  // NOTE: We do not use the server socket's address directly because
+  // this contains a `0.0.0.0` IP. According to RFC1122, this is an
+  // invalid address, except when used to resolve a host's address
+  // for the first time.
+  // See: https://tools.ietf.org/html/rfc1122#section-3.2.1.3
+  Address address(process::address().ip, any_address->port);
 
   Future<Socket> accept = server->accept();
 
-  Future<http::Connection> connect = http::connect(address.get());
+  Future<http::Connection> connect = http::connect(address);
 
   AWAIT_READY(connect);
   http::Connection connection = connect.get();
@@ -1818,7 +1830,7 @@ TEST_F(HttpServeTest, Pipelining)
     .WillOnce(DoAll(FutureArg<0>(&request3), Return(promise3.future())))
     .WillRepeatedly(Return(http::OK()));
 
-  http::URL url("http", address->hostname().get(), address->port, "/");
+  http::URL url("http", address.hostname().get(), address.port, "/");
 
   http::Request request;
   request.method = "GET";
@@ -1873,12 +1885,20 @@ TEST_F(HttpServeTest, Discard)
   ASSERT_SOME(server->bind(Address::ANY_ANY()));
   ASSERT_SOME(server->listen(1));
 
-  Try<Address> address = server->address();
-  ASSERT_SOME(address);
+  Try<Address> any_address = server->address();
+  ASSERT_SOME(any_address);
+
+  // Connect to the IP from the libprocess library, but use the port
+  // from the `bind` call above. The libprocess IP will always report
+  // a locally bindable IP, meaning it will also work for the server
+  // socket above.
+  //
+  // See the comment in `HttpServeTest.Pipelining` for more details.
+  Address address(process::address().ip, any_address->port);
 
   Future<Socket> accept = server->accept();
 
-  Future<http::Connection> connect = http::connect(address.get());
+  Future<http::Connection> connect = http::connect(address);
 
   AWAIT_READY(connect);
   http::Connection connection = connect.get();
@@ -1904,7 +1924,7 @@ TEST_F(HttpServeTest, Discard)
   EXPECT_CALL(handler, handle(_))
     .WillOnce(DoAll(FutureArg<0>(&request1), Return(promise1.future())));
 
-  http::URL url("http", address->hostname().get(), address->port, "/");
+  http::URL url("http", address.hostname().get(), address.port, "/");
 
   http::Request request;
   request.method = "GET";