Tests that the profiler's HTTP endpoints return the correct responses based on whether or not the profiler has been enabled.
| 74 | // Tests that the profiler's HTTP endpoints return the correct responses |
| 75 | // based on whether or not the profiler has been enabled. |
| 76 | TEST_F(ProfilerTest, StartAndStop) |
| 77 | { |
| 78 | UPID upid("profiler", process::address()); |
| 79 | |
| 80 | Future<Response> response = http::get(upid, "start"); |
| 81 | #ifdef ENABLE_GPERFTOOLS |
| 82 | Option<string> profilerEnabled = os::getenv("LIBPROCESS_ENABLE_PROFILER"); |
| 83 | |
| 84 | if (profilerEnabled.isSome() && profilerEnabled.get() == "1") { |
| 85 | AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response); |
| 86 | AWAIT_EXPECT_RESPONSE_BODY_EQ("Profiler started.\n", response); |
| 87 | |
| 88 | response = http::get(upid, "stop"); |
| 89 | AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response); |
| 90 | } else { |
| 91 | AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response); |
| 92 | AWAIT_EXPECT_RESPONSE_BODY_EQ( |
| 93 | "The profiler is not enabled. To enable the profiler, libprocess must " |
| 94 | "be started with LIBPROCESS_ENABLE_PROFILER=1 in the environment.\n", |
| 95 | response); |
| 96 | |
| 97 | response = http::get(upid, "stop"); |
| 98 | AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response); |
| 99 | AWAIT_EXPECT_RESPONSE_BODY_EQ("Profiler not running.\n", response); |
| 100 | } |
| 101 | #else |
| 102 | AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response); |
| 103 | AWAIT_EXPECT_RESPONSE_BODY_EQ( |
| 104 | "Perftools is disabled. To enable perftools, " |
| 105 | "configure libprocess with --enable-perftools.\n", |
| 106 | response); |
| 107 | |
| 108 | response = http::get(upid, "stop"); |
| 109 | AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response); |
| 110 | AWAIT_EXPECT_RESPONSE_BODY_EQ( |
| 111 | "Perftools is disabled. To enable perftools, " |
| 112 | "configure libprocess with --enable-perftools.\n", |
| 113 | response); |
| 114 | #endif |
| 115 | } |
| 116 | |
| 117 | |
| 118 | // Tests that the profiler's HTTP endpoints reject unauthenticated |
nothing calls this directly
no test coverage detected