async works

pull/9205/head
yang-g 8 years ago
parent 8e708b12cb
commit a3c95529c7
  1. 2
      src/cpp/server/server_cc.cc
  2. 128
      test/cpp/end2end/health_service_end2end_test.cc

@ -617,10 +617,8 @@ bool Server::Start(ServerCompletionQueue** cqs, size_t num_cqs) {
auto* default_hc_service = new DefaultHealthCheckService; auto* default_hc_service = new DefaultHealthCheckService;
health_check_service_.reset(default_hc_service); health_check_service_.reset(default_hc_service);
if (!sync_server_cqs_->empty()) { // Has sync methods. if (!sync_server_cqs_->empty()) { // Has sync methods.
gpr_log(GPR_ERROR, "register sync"); // XXX
RegisterService(nullptr, default_hc_service->GetSyncHealthCheckService()); RegisterService(nullptr, default_hc_service->GetSyncHealthCheckService());
} else { } else {
gpr_log(GPR_ERROR, "register async"); // XXX
async_health_service = default_hc_service->GetAsyncHealthCheckService(); async_health_service = default_hc_service->GetAsyncHealthCheckService();
RegisterService(nullptr, async_health_service); RegisterService(nullptr, async_health_service);
} }

@ -120,6 +120,14 @@ class CustomHealthCheckService : public HealthCheckServiceInterface {
HealthCheckServiceImpl* impl_; // not owned HealthCheckServiceImpl* impl_; // not owned
}; };
void LoopCompletionQueue(ServerCompletionQueue* cq) {
void* tag;
bool ok;
while (cq->Next(&tag, &ok)) {
abort(); // Nothing should come out of the cq.
}
}
class HealthServiceEnd2endTest : public ::testing::Test { class HealthServiceEnd2endTest : public ::testing::Test {
protected: protected:
HealthServiceEnd2endTest() {} HealthServiceEnd2endTest() {}
@ -160,6 +168,7 @@ class HealthServiceEnd2endTest : public ::testing::Test {
if (cq_thread_.joinable()) { if (cq_thread_.joinable()) {
cq_thread_.join(); cq_thread_.join();
} }
LoopCompletionQueue(cq_.get());
} }
} }
@ -223,9 +232,9 @@ class HealthServiceEnd2endTest : public ::testing::Test {
TestServiceImpl echo_test_service_; TestServiceImpl echo_test_service_;
HealthCheckServiceImpl health_check_service_impl_; HealthCheckServiceImpl health_check_service_impl_;
std::unique_ptr<Health::Stub> hc_stub_; std::unique_ptr<Health::Stub> hc_stub_;
std::unique_ptr<ServerCompletionQueue> cq_;
std::unique_ptr<Server> server_; std::unique_ptr<Server> server_;
std::ostringstream server_address_; std::ostringstream server_address_;
std::unique_ptr<ServerCompletionQueue> cq_;
std::thread cq_thread_; std::thread cq_thread_;
}; };
@ -242,69 +251,60 @@ TEST_F(HealthServiceEnd2endTest, DefaultHealthServiceDisabled) {
SendHealthCheckRpc("", Status(StatusCode::UNIMPLEMENTED, "")); SendHealthCheckRpc("", Status(StatusCode::UNIMPLEMENTED, ""));
} }
// TEST_F(HealthServiceEnd2endTest, DefaultHealthService) { TEST_F(HealthServiceEnd2endTest, DefaultHealthService) {
// EnableDefaultHealthCheckService(true); EnableDefaultHealthCheckService(true);
// EXPECT_TRUE(DefaultHealthCheckServiceEnabled()); EXPECT_TRUE(DefaultHealthCheckServiceEnabled());
// SetUpServer(true, false, nullptr); SetUpServer(true, false, nullptr);
// VerifyHealthCheckService(); VerifyHealthCheckService();
//
// // The default service has a size limit of the service name. // The default service has a size limit of the service name.
// const grpc::string kTooLongServiceName(201, 'x'); const grpc::string kTooLongServiceName(201, 'x');
// SendHealthCheckRpc(kTooLongServiceName, SendHealthCheckRpc(kTooLongServiceName,
// Status(StatusCode::INVALID_ARGUMENT, "")); Status(StatusCode::INVALID_ARGUMENT, ""));
// } }
//
// void LoopCompletionQueue(ServerCompletionQueue* cq) { TEST_F(HealthServiceEnd2endTest, DefaultHealthServiceAsync) {
// void* tag; EnableDefaultHealthCheckService(true);
// bool ok; EXPECT_TRUE(DefaultHealthCheckServiceEnabled());
// while (cq->Next(&tag, &ok)) { SetUpServer(false, false, nullptr);
// abort(); // Nothing should come out of the cq. cq_thread_ = std::thread(LoopCompletionQueue, cq_.get());
// } VerifyHealthCheckService();
// gpr_log(GPR_ERROR, "returning from thread");
// } // The default service has a size limit of the service name.
// const grpc::string kTooLongServiceName(201, 'x');
// TEST_F(HealthServiceEnd2endTest, DefaultHealthServiceAsync) { SendHealthCheckRpc(kTooLongServiceName,
// EnableDefaultHealthCheckService(true); Status(StatusCode::INVALID_ARGUMENT, ""));
// EXPECT_TRUE(DefaultHealthCheckServiceEnabled()); }
// SetUpServer(false, false, nullptr);
// cq_thread_ = std::thread(LoopCompletionQueue, cq_.get()); // Provide an empty service to disable the default service.
// VerifyHealthCheckService(); TEST_F(HealthServiceEnd2endTest, ExplicitlyDisableViaOverride) {
// EnableDefaultHealthCheckService(true);
// // The default service has a size limit of the service name. EXPECT_TRUE(DefaultHealthCheckServiceEnabled());
// const grpc::string kTooLongServiceName(201, 'x'); std::unique_ptr<HealthCheckServiceInterface> empty_service;
// SendHealthCheckRpc(kTooLongServiceName, SetUpServer(true, true, std::move(empty_service));
// Status(StatusCode::INVALID_ARGUMENT, "")); HealthCheckServiceInterface* service = server_->GetHealthCheckService();
// } EXPECT_TRUE(service == nullptr);
//
// // Provide an empty service to disable the default service. ResetStubs();
// TEST_F(HealthServiceEnd2endTest, ExplicitlyDisableViaOverride) {
// EnableDefaultHealthCheckService(true); SendHealthCheckRpc("", Status(StatusCode::UNIMPLEMENTED, ""));
// EXPECT_TRUE(DefaultHealthCheckServiceEnabled()); }
// std::unique_ptr<HealthCheckServiceInterface> empty_service;
// SetUpServer(true, true, std::move(empty_service)); // Provide an explicit override of health checking service interface.
// HealthCheckServiceInterface* service = server_->GetHealthCheckService(); TEST_F(HealthServiceEnd2endTest, ExplicitlyOverride) {
// EXPECT_TRUE(service == nullptr); EnableDefaultHealthCheckService(true);
// EXPECT_TRUE(DefaultHealthCheckServiceEnabled());
// ResetStubs(); std::unique_ptr<HealthCheckServiceInterface> override_service(
// new CustomHealthCheckService(&health_check_service_impl_));
// SendHealthCheckRpc("", Status(StatusCode::UNIMPLEMENTED, "")); HealthCheckServiceInterface* underlying_service = override_service.get();
// } SetUpServer(false, true, std::move(override_service));
// HealthCheckServiceInterface* service = server_->GetHealthCheckService();
// // Provide an explicit override of health checking service interface. EXPECT_TRUE(service == underlying_service);
// TEST_F(HealthServiceEnd2endTest, ExplicitlyOverride) {
// EnableDefaultHealthCheckService(true); ResetStubs();
// EXPECT_TRUE(DefaultHealthCheckServiceEnabled());
// std::unique_ptr<HealthCheckServiceInterface> override_service( VerifyHealthCheckService();
// new CustomHealthCheckService(&health_check_service_impl_)); }
// HealthCheckServiceInterface* underlying_service = override_service.get();
// SetUpServer(false, true, std::move(override_service));
// HealthCheckServiceInterface* service = server_->GetHealthCheckService();
// EXPECT_TRUE(service == underlying_service);
//
// ResetStubs();
//
// VerifyHealthCheckService();
// }
} // namespace } // namespace
} // namespace testing } // namespace testing

Loading…
Cancel
Save