Add a check against potential failure to bring up client binary

pull/1757/head
Yang Gao 10 years ago
parent 5c19eb8ff6
commit a9b5de8131
  1. 36
      test/cpp/end2end/server_crash_test.cc

@ -69,10 +69,15 @@ namespace testing {
namespace {
class ServiceImpl GRPC_FINAL : public ::grpc::cpp::test::util::TestService::Service {
class ServiceImpl GRPC_FINAL
: public ::grpc::cpp::test::util::TestService::Service {
public:
ServiceImpl() : bidi_stream_count_(0), response_stream_count_(0) {}
Status BidiStream(ServerContext* context,
ServerReaderWriter<EchoResponse, EchoRequest>* stream)
GRPC_OVERRIDE {
bidi_stream_count_++;
EchoRequest request;
EchoResponse response;
while (stream->Read(&request)) {
@ -87,6 +92,7 @@ class ServiceImpl GRPC_FINAL : public ::grpc::cpp::test::util::TestService::Serv
Status ResponseStream(ServerContext* context, const EchoRequest* request,
ServerWriter<EchoResponse>* writer) GRPC_OVERRIDE {
EchoResponse response;
response_stream_count_++;
for (int i = 0;; i++) {
std::ostringstream msg;
msg << "Hello " << i;
@ -96,23 +102,27 @@ class ServiceImpl GRPC_FINAL : public ::grpc::cpp::test::util::TestService::Serv
}
return Status::OK;
}
int bidi_stream_count() { return bidi_stream_count_; }
int response_stream_count() { return response_stream_count_; }
private:
int bidi_stream_count_;
int response_stream_count_;
};
class CrashTest : public ::testing::Test {
protected:
CrashTest() {}
std::unique_ptr<Server>
CreateServerAndClient(const std::string& mode) {
std::unique_ptr<Server> CreateServerAndClient(const std::string& mode) {
auto port = grpc_pick_unused_port_or_die();
std::ostringstream addr_stream;
addr_stream << "localhost:" << port;
auto addr = addr_stream.str();
client_.reset(new SubProcess({
g_root + "/server_crash_test_client",
"--address=" + addr,
"--mode=" + mode
}));
client_.reset(new SubProcess({g_root + "/server_crash_test_client",
"--address=" + addr, "--mode=" + mode}));
GPR_ASSERT(client_);
ServerBuilder builder;
@ -121,9 +131,11 @@ class CrashTest : public ::testing::Test {
return builder.BuildAndStart();
}
void KillClient() {
client_.reset();
}
void KillClient() { client_.reset(); }
bool HadOneBidiStream() { return service_.bidi_stream_count() == 1; }
bool HadOneResponseStream() { return service_.response_stream_count() == 1; }
private:
std::unique_ptr<SubProcess> client_;
@ -136,6 +148,7 @@ TEST_F(CrashTest, ResponseStream) {
gpr_sleep_until(gpr_time_add(gpr_now(), gpr_time_from_seconds(5)));
KillClient();
server->Shutdown();
GPR_ASSERT(HadOneResponseStream());
}
TEST_F(CrashTest, BidiStream) {
@ -144,6 +157,7 @@ TEST_F(CrashTest, BidiStream) {
gpr_sleep_until(gpr_time_add(gpr_now(), gpr_time_from_seconds(5)));
KillClient();
server->Shutdown();
GPR_ASSERT(HadOneBidiStream());
}
} // namespace

Loading…
Cancel
Save