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 2015/12/13 20:35:11 UTC
[1/2] mesos git commit: Fixed a connection leak in ProcessTest.Http1.
Repository: mesos
Updated Branches:
refs/heads/master f32c1ba64 -> 6eb2f98b3
Fixed a connection leak in ProcessTest.Http1.
Review: https://reviews.apache.org/r/41318
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/3fb0801e
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/3fb0801e
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/3fb0801e
Branch: refs/heads/master
Commit: 3fb0801ed3c3d94b921e1c2074a662b62786d0ee
Parents: f32c1ba
Author: Benjamin Mahler <be...@gmail.com>
Authored: Sat Dec 12 14:27:33 2015 -0800
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Sun Dec 13 11:30:47 2015 -0800
----------------------------------------------------------------------
3rdparty/libprocess/src/tests/process_tests.cpp | 64 ++++++++++++++++----
1 file changed, 52 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/3fb0801e/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 3970dd8..df388ed 100644
--- a/3rdparty/libprocess/src/tests/process_tests.cpp
+++ b/3rdparty/libprocess/src/tests/process_tests.cpp
@@ -1379,7 +1379,7 @@ TEST(ProcessTest, Remote)
}
-// Like the 'remote' test but uses http::post.
+// Like the 'remote' test but uses http::connect.
TEST(ProcessTest, Http1)
{
ASSERT_TRUE(GTEST_IS_THREADSAFE);
@@ -1387,17 +1387,33 @@ TEST(ProcessTest, Http1)
RemoteProcess process;
spawn(process);
+ http::URL url = http::URL(
+ "http",
+ process.self().address.ip,
+ process.self().address.port,
+ process.self().id + "/handler");
+
+ Future<http::Connection> connect = http::connect(url);
+ AWAIT_READY(connect);
+
+ http::Connection connection = connect.get();
+
Future<UPID> pid;
Future<string> body;
EXPECT_CALL(process, handler(_, _))
.WillOnce(DoAll(FutureArg<0>(&pid),
FutureArg<1>(&body)));
- http::Headers headers;
- headers["User-Agent"] = "libprocess/";
+ http::Request request;
+ request.method = "POST";
+ request.url = url;
+ request.headers["User-Agent"] = "libprocess/";
+ request.body = "hello world";
- Future<http::Response> response =
- http::post(process.self(), "handler", headers, "hello world");
+ // Send the libprocess request. Note that we will not
+ // receive a 202 due to the use of the `User-Agent`
+ // header, therefore we need to explicitly disconnect!
+ Future<http::Response> response = connection.send(request);
AWAIT_READY(body);
ASSERT_EQ("hello world", body.get());
@@ -1405,12 +1421,17 @@ TEST(ProcessTest, Http1)
AWAIT_READY(pid);
ASSERT_EQ(UPID(), pid.get());
+ EXPECT_TRUE(response.isPending());
+
+ AWAIT_READY(connection.disconnect());
+
terminate(process);
wait(process);
}
-// Like 'http1' but using a 'Libprocess-From' header.
+// Like 'http1' but uses the 'Libprocess-From' header. We can
+// also use http::post here since we expect a 202 response.
TEST(ProcessTest, Http2)
{
ASSERT_TRUE(GTEST_IS_THREADSAFE);
@@ -1762,30 +1783,49 @@ TEST(ProcessTest, PercentEncodedURLs)
spawn(process);
// Construct the PID using percent-encoding.
- UPID pid("id%2842%29", process.self().address);
+ http::URL url = http::URL(
+ "http",
+ process.self().address.ip,
+ process.self().address.port,
+ http::encode(process.self().id) + "/handler1");
+
+ Future<http::Connection> connect = http::connect(url);
+ AWAIT_READY(connect);
+
+ http::Connection connection = connect.get();
// Mimic a libprocess message sent to an installed handler.
Future<Nothing> handler1;
EXPECT_CALL(process, handler1(_, _))
.WillOnce(FutureSatisfy(&handler1));
- http::Headers headers;
- headers["User-Agent"] = "libprocess/";
+ http::Request request;
+ request.method = "POST";
+ request.url = url;
+ request.headers["User-Agent"] = "libprocess/";
- Future<http::Response> response = http::post(pid, "handler1", headers);
+ // Send the libprocess request. Note that we will not
+ // receive a 202 due to the use of the `User-Agent`
+ // header, therefore we need to explicitly disconnect!
+ Future<http::Response> response = connection.send(request);
AWAIT_READY(handler1);
+ EXPECT_TRUE(response.isPending());
+
+ AWAIT_READY(connection.disconnect());
// Now an HTTP request.
EXPECT_CALL(process, handler2(_))
.WillOnce(Return(http::OK()));
+ // Construct the PID using percent-encoding.
+ UPID pid(http::encode(process.self().id), process.self().address);
+
response = http::get(pid, "handler2");
AWAIT_READY(response);
EXPECT_EQ(http::Status::OK, response->code);
- EXPECT_EQ(http::Status::string(http::Status::OK),
- response->status);
+ EXPECT_EQ(http::Status::string(http::Status::OK), response->status);
terminate(process);
wait(process);
[2/2] mesos git commit: Clarified Subprocess PIPE usage in Subprocess
tests.
Posted by bm...@apache.org.
Clarified Subprocess PIPE usage in Subprocess tests.
Review: https://reviews.apache.org/r/41320
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/6eb2f98b
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/6eb2f98b
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/6eb2f98b
Branch: refs/heads/master
Commit: 6eb2f98b3f4f770319a63da31459459628b48b46
Parents: 3fb0801
Author: Benjamin Mahler <be...@gmail.com>
Authored: Sat Dec 12 11:07:22 2015 -0800
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Sun Dec 13 11:30:48 2015 -0800
----------------------------------------------------------------------
.../libprocess/src/tests/subprocess_tests.cpp | 76 ++++++++++----------
1 file changed, 38 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/6eb2f98b/3rdparty/libprocess/src/tests/subprocess_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/subprocess_tests.cpp b/3rdparty/libprocess/src/tests/subprocess_tests.cpp
index 869b920..8f0a313 100644
--- a/3rdparty/libprocess/src/tests/subprocess_tests.cpp
+++ b/3rdparty/libprocess/src/tests/subprocess_tests.cpp
@@ -143,9 +143,9 @@ TEST_F(SubprocessTest, PipeOutput)
// Standard out.
Try<Subprocess> s = subprocess(
"echo hello",
+ Subprocess::FD(STDIN_FILENO),
Subprocess::PIPE(),
- Subprocess::PIPE(),
- Subprocess::PIPE());
+ Subprocess::FD(STDERR_FILENO));
ASSERT_SOME(s);
ASSERT_SOME(s.get().out());
@@ -169,8 +169,8 @@ TEST_F(SubprocessTest, PipeOutput)
// Standard error.
s = subprocess(
"echo hello 1>&2",
- Subprocess::PIPE(),
- Subprocess::PIPE(),
+ Subprocess::FD(STDIN_FILENO),
+ Subprocess::FD(STDOUT_FILENO),
Subprocess::PIPE());
ASSERT_SOME(s);
@@ -200,7 +200,7 @@ TEST_F(SubprocessTest, PipeInput)
"read word ; echo $word",
Subprocess::PIPE(),
Subprocess::PIPE(),
- Subprocess::PIPE());
+ Subprocess::FD(STDERR_FILENO));
ASSERT_SOME(s);
ASSERT_SOME(s.get().in());
@@ -230,9 +230,9 @@ TEST_F(SubprocessTest, PipeRedirect)
{
Try<Subprocess> s = subprocess(
"echo 'hello world'",
+ Subprocess::FD(STDIN_FILENO),
Subprocess::PIPE(),
- Subprocess::PIPE(),
- Subprocess::PIPE());
+ Subprocess::FD(STDERR_FILENO));
ASSERT_SOME(s);
@@ -284,9 +284,9 @@ TEST_F(SubprocessTest, PathOutput)
// Standard out.
Try<Subprocess> s = subprocess(
"echo hello",
- Subprocess::PIPE(),
+ Subprocess::FD(STDIN_FILENO),
Subprocess::PATH(out),
- Subprocess::PIPE());
+ Subprocess::FD(STDERR_FILENO));
ASSERT_SOME(s);
@@ -312,8 +312,8 @@ TEST_F(SubprocessTest, PathOutput)
// Standard error.
s = subprocess(
"echo hello 1>&2",
- Subprocess::PIPE(),
- Subprocess::PIPE(),
+ Subprocess::FD(STDIN_FILENO),
+ Subprocess::FD(STDOUT_FILENO),
Subprocess::PATH(err));
ASSERT_SOME(s);
@@ -349,7 +349,7 @@ TEST_F(SubprocessTest, PathInput)
"read word ; echo $word",
Subprocess::PATH(in),
Subprocess::PIPE(),
- Subprocess::PIPE());
+ Subprocess::FD(STDERR_FILENO));
ASSERT_SOME(s);
ASSERT_SOME(s.get().out());
@@ -387,9 +387,9 @@ TEST_F(SubprocessTest, FdOutput)
Try<Subprocess> s = subprocess(
"echo hello",
- Subprocess::PIPE(),
+ Subprocess::FD(STDIN_FILENO),
Subprocess::FD(outFd.get()),
- Subprocess::PIPE());
+ Subprocess::FD(STDERR_FILENO));
ASSERT_SOME(os::close(outFd.get()));
ASSERT_SOME(s);
@@ -423,8 +423,8 @@ TEST_F(SubprocessTest, FdOutput)
s = subprocess(
"echo hello 1>&2",
- Subprocess::PIPE(),
- Subprocess::PIPE(),
+ Subprocess::FD(STDIN_FILENO),
+ Subprocess::FD(STDOUT_FILENO),
Subprocess::FD(errFd.get()));
ASSERT_SOME(os::close(errFd.get()));
@@ -464,7 +464,7 @@ TEST_F(SubprocessTest, FdInput)
"read word ; echo $word",
Subprocess::FD(inFd.get()),
Subprocess::PIPE(),
- Subprocess::PIPE());
+ Subprocess::FD(STDERR_FILENO));
ASSERT_SOME(os::close(inFd.get()));
@@ -571,9 +571,9 @@ TEST_F(SubprocessTest, Flags)
Try<Subprocess> s = subprocess(
"/bin/echo",
vector<string>(1, "echo"),
- Subprocess::PIPE(),
+ Subprocess::FD(STDIN_FILENO),
Subprocess::PATH(out),
- Subprocess::PIPE(),
+ Subprocess::FD(STDERR_FILENO),
flags);
ASSERT_SOME(s);
@@ -635,9 +635,9 @@ TEST_F(SubprocessTest, Environment)
Try<Subprocess> s = subprocess(
"echo $MESSAGE",
+ Subprocess::FD(STDIN_FILENO),
Subprocess::PIPE(),
- Subprocess::PIPE(),
- Subprocess::PIPE(),
+ Subprocess::FD(STDERR_FILENO),
environment);
ASSERT_SOME(s);
@@ -666,9 +666,9 @@ TEST_F(SubprocessTest, Environment)
s = subprocess(
"echo $MESSAGE0 $MESSAGE1",
+ Subprocess::FD(STDIN_FILENO),
Subprocess::PIPE(),
- Subprocess::PIPE(),
- Subprocess::PIPE(),
+ Subprocess::FD(STDERR_FILENO),
environment);
ASSERT_SOME(s);
@@ -700,9 +700,9 @@ TEST_F(SubprocessTest, EnvironmentWithSpaces)
Try<Subprocess> s = subprocess(
"echo $MESSAGE",
+ Subprocess::FD(STDIN_FILENO),
Subprocess::PIPE(),
- Subprocess::PIPE(),
- Subprocess::PIPE(),
+ Subprocess::FD(STDERR_FILENO),
environment);
ASSERT_SOME(s);
@@ -734,9 +734,9 @@ TEST_F(SubprocessTest, EnvironmentWithSpacesAndQuotes)
Try<Subprocess> s = subprocess(
"echo $MESSAGE",
+ Subprocess::FD(STDIN_FILENO),
Subprocess::PIPE(),
- Subprocess::PIPE(),
- Subprocess::PIPE(),
+ Subprocess::FD(STDERR_FILENO),
environment);
ASSERT_SOME(s);
@@ -771,9 +771,9 @@ TEST_F(SubprocessTest, EnvironmentOverride)
Try<Subprocess> s = subprocess(
"echo $MESSAGE1 $MESSAGE2",
+ Subprocess::FD(STDIN_FILENO),
Subprocess::PIPE(),
- Subprocess::PIPE(),
- Subprocess::PIPE(),
+ Subprocess::FD(STDERR_FILENO),
environment);
ASSERT_SOME(s);
@@ -816,9 +816,9 @@ TEST_F(SubprocessTest, Setup)
// chdir().
Try<Subprocess> s = subprocess(
"echo hello world > file",
- Subprocess::PIPE(),
- Subprocess::PIPE(),
- Subprocess::PIPE(),
+ Subprocess::FD(STDIN_FILENO),
+ Subprocess::FD(STDOUT_FILENO),
+ Subprocess::FD(STDERR_FILENO),
None(),
lambda::bind(&setupChdir, directory.get()));
@@ -855,9 +855,9 @@ TEST_F(SubprocessTest, SetupStatus)
// Exit 0 && setup 1.
Try<Subprocess> s = subprocess(
"exit 0",
- Subprocess::PIPE(),
- Subprocess::PIPE(),
- Subprocess::PIPE(),
+ Subprocess::FD(STDIN_FILENO),
+ Subprocess::FD(STDOUT_FILENO),
+ Subprocess::FD(STDERR_FILENO),
None(),
lambda::bind(&setupStatus, 1));
@@ -883,9 +883,9 @@ TEST_F(SubprocessTest, SetupStatus)
// Exit 1 && setup 0.
s = subprocess(
"exit 1",
- Subprocess::PIPE(),
- Subprocess::PIPE(),
- Subprocess::PIPE(),
+ Subprocess::FD(STDIN_FILENO),
+ Subprocess::FD(STDOUT_FILENO),
+ Subprocess::FD(STDERR_FILENO),
None(),
lambda::bind(&setupStatus, 0));