Repository: mesos Updated Branches: refs/heads/master 657dc0506 -> abd1751aa
Added explicit scopes for clarity in HTTPTest.Endpoints test. Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/a94a8a67 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/a94a8a67 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/a94a8a67 Branch: refs/heads/master Commit: a94a8a67900ceabdce5a83233e66938d6dd1917a Parents: 657dc05 Author: Alexander Rukletsov <al...@apache.org> Authored: Thu Jan 25 19:48:34 2018 +0100 Committer: Alexander Rukletsov <al...@apache.org> Committed: Thu Jan 25 20:04:13 2018 +0100 ---------------------------------------------------------------------- 3rdparty/libprocess/src/tests/http_tests.cpp | 95 ++++++++++++----------- 1 file changed, 51 insertions(+), 44 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/a94a8a67/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 f79d366..e23f284 100644 --- a/3rdparty/libprocess/src/tests/http_tests.cpp +++ b/3rdparty/libprocess/src/tests/http_tests.cpp @@ -237,66 +237,73 @@ TEST_P(HTTPTest, Endpoints) Http http; // First hit '/body' (using explicit sockets and HTTP/1.0). - Try<inet::Socket> create = inet::Socket::create(); - ASSERT_SOME(create); - - inet::Socket socket = create.get(); - - AWAIT_READY(socket.connect(http.process->self().address)); + { + Try<inet::Socket> create = inet::Socket::create(); + ASSERT_SOME(create); - std::ostringstream out; - out << "GET /" << http.process->self().id << "/body" - << " HTTP/1.0\r\n" - << "Connection: Keep-Alive\r\n" - << "\r\n"; + inet::Socket socket = create.get(); - const string data = out.str(); + AWAIT_READY(socket.connect(http.process->self().address)); - EXPECT_CALL(*http.process, body(_)) - .WillOnce(Return(http::OK())); + std::ostringstream out; + out << "GET /" << http.process->self().id << "/body" + << " HTTP/1.0\r\n" + << "Connection: Keep-Alive\r\n" + << "\r\n"; - AWAIT_READY(socket.send(data)); + const string data = out.str(); + const string response = "HTTP/1.1 200 OK"; - string response = "HTTP/1.1 200 OK"; + EXPECT_CALL(*http.process, body(_)) + .WillOnce(Return(http::OK())); - AWAIT_EXPECT_EQ(response, socket.recv(response.size())); + AWAIT_READY(socket.send(data)); + AWAIT_EXPECT_EQ(response, socket.recv(response.size())); + } - // Now hit '/pipe' (by using http::get). - http::Pipe pipe; - http::OK ok; - ok.type = http::Response::PIPE; - ok.reader = pipe.reader(); + // Test that an endpoint handler failure results in a 500. + { + EXPECT_CALL(*http.process, body(_)) + .WillOnce(Return(Future<http::Response>::failed("failure"))); - Future<Nothing> request; - EXPECT_CALL(*http.process, pipe(_)) - .WillOnce(DoAll(FutureSatisfy(&request), - Return(ok))); + Future<http::Response> response = + http::get(http.process->self(), "body", None(), None(), GetParam()); - Future<http::Response> future = - http::get(http.process->self(), "pipe", None(), None(), GetParam()); + AWAIT_ASSERT_RESPONSE_STATUS_EQ( + http::InternalServerError().status, + response); + EXPECT_EQ("failure", response->body); + } - AWAIT_READY(request); + // Now hit '/pipe' (by using http::get). + { + http::Pipe pipe; + http::OK ok; + ok.type = http::Response::PIPE; + ok.reader = pipe.reader(); - // Write the response. - http::Pipe::Writer writer = pipe.writer(); - EXPECT_TRUE(writer.write("Hello World\n")); - EXPECT_TRUE(writer.close()); + Future<Nothing> request; + EXPECT_CALL(*http.process, pipe(_)) + .WillOnce(DoAll(FutureSatisfy(&request), + Return(ok))); - AWAIT_READY(future); - EXPECT_EQ(http::Status::OK, future->code); - EXPECT_EQ(http::Status::string(http::Status::OK), future->status); + Future<http::Response> future = + http::get(http.process->self(), "pipe", None(), None(), GetParam()); - EXPECT_SOME_EQ("chunked", future->headers.get("Transfer-Encoding")); - EXPECT_EQ("Hello World\n", future->body); + AWAIT_READY(request); - // Test that an endpoint handler failure results in a 500. - EXPECT_CALL(*http.process, body(_)) - .WillOnce(Return(Future<http::Response>::failed("failure"))); + // Write the response. + http::Pipe::Writer writer = pipe.writer(); + EXPECT_TRUE(writer.write("Hello World\n")); + EXPECT_TRUE(writer.close()); - future = http::get(http.process->self(), "body", None(), None(), GetParam()); + AWAIT_READY(future); + EXPECT_EQ(http::Status::OK, future->code); + EXPECT_EQ(http::Status::string(http::Status::OK), future->status); - AWAIT_ASSERT_RESPONSE_STATUS_EQ(http::InternalServerError().status, future); - EXPECT_EQ("failure", future->body); + EXPECT_SOME_EQ("chunked", future->headers.get("Transfer-Encoding")); + EXPECT_EQ("Hello World\n", future->body); + } }