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 2016/02/05 06:18:44 UTC
[4/8] mesos git commit: Added unit tests for hitting the /help
endpoints of a process.
Added unit tests for hitting the /help endpoints of a process.
These unit tests make sure that help endpoints are up and
running for a process's installed routes. They also ensure that
deleting a process removes the help information for all of it's routes
(to make sure stale information isn't sticking around if a new process
comes along with the same id later).
Review: https://reviews.apache.org/r/43219/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/30042c4e
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/30042c4e
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/30042c4e
Branch: refs/heads/master
Commit: 30042c4e39aebfaed21978c79a7ed44cf96d982f
Parents: b2cefc6
Author: Kevin Klues <kl...@gmail.com>
Authored: Thu Feb 4 19:52:45 2016 -0800
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Thu Feb 4 21:18:17 2016 -0800
----------------------------------------------------------------------
3rdparty/libprocess/src/tests/http_tests.cpp | 102 ++++++++++++++++++++++
1 file changed, 102 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/30042c4e/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 66d185e..dfd93d9 100644
--- a/3rdparty/libprocess/src/tests/http_tests.cpp
+++ b/3rdparty/libprocess/src/tests/http_tests.cpp
@@ -180,6 +180,108 @@ TEST(HTTPTest, Endpoints)
}
+TEST(HTTPTest, EndpointsHelp)
+{
+ Http http;
+ PID<HttpProcess> pid = http.process->self();
+
+ // Wait until the HttpProcess initialization has run so
+ // that the route calls have completed.
+ std::function<Nothing()> f = []() { return Nothing(); };
+
+ Future<Nothing> initialized = dispatch(pid, f);
+ AWAIT_READY(initialized);
+
+ // Hit '/help' and wait for a 200 OK response.
+ http::URL url = http::URL(
+ "http",
+ http.process->self().address.ip,
+ http.process->self().address.port,
+ "/help");
+
+ Future<http::Response> response = http::get(url);
+
+ AWAIT_READY(response);
+ EXPECT_EQ(http::Status::OK, response->code);
+ EXPECT_EQ(http::Status::string(http::Status::OK), response->status);
+
+ // Hit '/help?format=json' and wait for a 200 OK response.
+ url = http::URL(
+ "http",
+ http.process->self().address.ip,
+ http.process->self().address.port,
+ "/help",
+ {{"format", "json"}});
+
+ response = http::get(url);
+
+ AWAIT_READY(response);
+ EXPECT_EQ(http::Status::OK, response->code);
+ EXPECT_EQ(http::Status::string(http::Status::OK), response->status);
+
+ // Assert that it is valid JSON
+ EXPECT_SOME(JSON::parse(response->body));
+
+ // Hit '/help/<id>/body' and wait for a 200 OK response.
+ url = http::URL(
+ "http",
+ http.process->self().address.ip,
+ http.process->self().address.port,
+ "/help/" + pid.id + "/body");
+
+ response = http::get(url);
+
+ AWAIT_READY(response);
+ EXPECT_EQ(http::Status::OK, response->code);
+ EXPECT_EQ(http::Status::string(http::Status::OK), response->status);
+}
+
+
+TEST(HTTPTest, EndpointsHelpRemoval)
+{
+ // Start up a new HttpProcess;
+ Owned<Http> http(new Http());
+ PID<HttpProcess> pid = http->process->self();
+
+ // Wait until the HttpProcess initialization has run so
+ // that the route calls have completed.
+ std::function<Nothing()> f = []() { return Nothing(); };
+
+ Future<Nothing> initialized = dispatch(pid, f);
+ AWAIT_READY(initialized);
+
+ // Hit '/help/<id>/body' and wait for a 200 OK response.
+ http::URL url = http::URL(
+ "http",
+ http->process->self().address.ip,
+ http->process->self().address.port,
+ "/help/" + pid.id + "/body");
+
+ Future<http::Response> response = http::get(url);
+
+ AWAIT_READY(response);
+ EXPECT_EQ(http::Status::OK, response->code);
+ EXPECT_EQ(http::Status::string(http::Status::OK), response->status);
+
+ // Delete the HttpProcess. This should remove all help endpoints
+ // for the process, in addition to its own endpoints.
+ http.reset();
+
+ // Hit '/help/<id>/bogus' and wait for a 400 BAD REQUEST response.
+ url = http::URL(
+ "http",
+ process::address().ip,
+ process::address().port,
+ "/help/" + pid.id + "/bogus");
+
+ response = http::get(url);
+
+ AWAIT_READY(response);
+ ASSERT_EQ(http::Status::BAD_REQUEST, response->code);
+ ASSERT_EQ(http::Status::string(http::Status::BAD_REQUEST), response->status);
+}
+
+
TEST(HTTPTest, PipeEOF)
{
http::Pipe pipe;