Make test more robust

pull/1888/head
Craig Tiller 10 years ago
parent 29f741fee9
commit f54f2d0586
  1. 26
      test/cpp/end2end/client_crash_test.cc

@ -90,15 +90,13 @@ class CrashTest : public ::testing::Test {
void KillServer() {
server_.reset();
// give some time for the TCP connection to drop
gpr_sleep_until(gpr_time_add(gpr_now(), gpr_time_from_seconds(1)));
}
private:
std::unique_ptr<SubProcess> server_;
};
TEST_F(CrashTest, KillAfterWrite) {
TEST_F(CrashTest, KillBeforeWrite) {
auto stub = CreateServerAndStub();
EchoRequest request;
@ -112,17 +110,18 @@ TEST_F(CrashTest, KillAfterWrite) {
EXPECT_TRUE(stream->Read(&response));
EXPECT_EQ(response.message(), request.message());
request.set_message("I'm going to kill you");
EXPECT_TRUE(stream->Write(request));
KillServer();
request.set_message("You should be dead");
// This may succeed or fail depending on the state of the TCP connection
stream->Write(request);
// But the read will definitely fail
EXPECT_FALSE(stream->Read(&response));
EXPECT_FALSE(stream->Finish().IsOk());
}
TEST_F(CrashTest, KillBeforeWrite) {
TEST_F(CrashTest, KillAfterWrite) {
auto stub = CreateServerAndStub();
EchoRequest request;
@ -136,10 +135,11 @@ TEST_F(CrashTest, KillBeforeWrite) {
EXPECT_TRUE(stream->Read(&response));
EXPECT_EQ(response.message(), request.message());
request.set_message("I'm going to kill you");
EXPECT_TRUE(stream->Write(request));
KillServer();
request.set_message("You should be dead");
EXPECT_FALSE(stream->Write(request));
EXPECT_FALSE(stream->Read(&response));
EXPECT_FALSE(stream->Finish().IsOk());
@ -161,5 +161,11 @@ int main(int argc, char** argv) {
grpc_test_init(argc, argv);
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
// Order seems to matter on these tests: run three times to eliminate that
for (int i = 0; i < 3; i++) {
if (RUN_ALL_TESTS() != 0) {
return 1;
}
}
return 0;
}

Loading…
Cancel
Save