|
|
@ -90,15 +90,13 @@ class CrashTest : public ::testing::Test { |
|
|
|
|
|
|
|
|
|
|
|
void KillServer() { |
|
|
|
void KillServer() { |
|
|
|
server_.reset(); |
|
|
|
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: |
|
|
|
private: |
|
|
|
std::unique_ptr<SubProcess> server_; |
|
|
|
std::unique_ptr<SubProcess> server_; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(CrashTest, KillAfterWrite) { |
|
|
|
TEST_F(CrashTest, KillBeforeWrite) { |
|
|
|
auto stub = CreateServerAndStub(); |
|
|
|
auto stub = CreateServerAndStub(); |
|
|
|
|
|
|
|
|
|
|
|
EchoRequest request; |
|
|
|
EchoRequest request; |
|
|
@ -112,17 +110,18 @@ TEST_F(CrashTest, KillAfterWrite) { |
|
|
|
EXPECT_TRUE(stream->Read(&response)); |
|
|
|
EXPECT_TRUE(stream->Read(&response)); |
|
|
|
EXPECT_EQ(response.message(), request.message()); |
|
|
|
EXPECT_EQ(response.message(), request.message()); |
|
|
|
|
|
|
|
|
|
|
|
request.set_message("I'm going to kill you"); |
|
|
|
|
|
|
|
EXPECT_TRUE(stream->Write(request)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
KillServer(); |
|
|
|
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->Read(&response)); |
|
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(stream->Finish().IsOk()); |
|
|
|
EXPECT_FALSE(stream->Finish().IsOk()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(CrashTest, KillBeforeWrite) { |
|
|
|
TEST_F(CrashTest, KillAfterWrite) { |
|
|
|
auto stub = CreateServerAndStub(); |
|
|
|
auto stub = CreateServerAndStub(); |
|
|
|
|
|
|
|
|
|
|
|
EchoRequest request; |
|
|
|
EchoRequest request; |
|
|
@ -136,10 +135,11 @@ TEST_F(CrashTest, KillBeforeWrite) { |
|
|
|
EXPECT_TRUE(stream->Read(&response)); |
|
|
|
EXPECT_TRUE(stream->Read(&response)); |
|
|
|
EXPECT_EQ(response.message(), request.message()); |
|
|
|
EXPECT_EQ(response.message(), request.message()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
request.set_message("I'm going to kill you"); |
|
|
|
|
|
|
|
EXPECT_TRUE(stream->Write(request)); |
|
|
|
|
|
|
|
|
|
|
|
KillServer(); |
|
|
|
KillServer(); |
|
|
|
|
|
|
|
|
|
|
|
request.set_message("You should be dead"); |
|
|
|
|
|
|
|
EXPECT_FALSE(stream->Write(request)); |
|
|
|
|
|
|
|
EXPECT_FALSE(stream->Read(&response)); |
|
|
|
EXPECT_FALSE(stream->Read(&response)); |
|
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(stream->Finish().IsOk()); |
|
|
|
EXPECT_FALSE(stream->Finish().IsOk()); |
|
|
@ -161,5 +161,11 @@ int main(int argc, char** argv) { |
|
|
|
|
|
|
|
|
|
|
|
grpc_test_init(argc, argv); |
|
|
|
grpc_test_init(argc, argv); |
|
|
|
::testing::InitGoogleTest(&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; |
|
|
|
} |
|
|
|
} |
|
|
|