aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2015-08-07 10:16:12 -0700
committerGravatar Craig Tiller <ctiller@google.com>2015-08-07 10:16:12 -0700
commit0ce5540a3f1528ac0c9d4b13d910a89c8cca9b90 (patch)
tree8d3fdf144b3e378cb1af0dfb2e206fcb38a07c15 /test
parentc72275dfd174993ffe555c2bd7ee381d4b62d97c (diff)
parentcec757f22a9932dc0f47640e18428300b75066f7 (diff)
Merge pull request #2811 from yang-g/channel_state_api
Channel state api
Diffstat (limited to 'test')
-rw-r--r--test/cpp/end2end/end2end_test.cc24
1 files changed, 23 insertions, 1 deletions
diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc
index 24d417d9e6..5f0749daa5 100644
--- a/test/cpp/end2end/end2end_test.cc
+++ b/test/cpp/end2end/end2end_test.cc
@@ -869,7 +869,8 @@ TEST_P(End2endTest, HugeResponse) {
}
namespace {
-void ReaderThreadFunc(ClientReaderWriter<EchoRequest, EchoResponse>* stream, gpr_event *ev) {
+void ReaderThreadFunc(ClientReaderWriter<EchoRequest, EchoResponse>* stream,
+ gpr_event *ev) {
EchoResponse resp;
gpr_event_set(ev, (void*)1);
while (stream->Read(&resp)) {
@@ -908,6 +909,27 @@ TEST_P(End2endTest, Peer) {
EXPECT_TRUE(CheckIsLocalhost(context.peer()));
}
+TEST_F(End2endTest, ChannelState) {
+ ResetStub(false);
+ // Start IDLE
+ EXPECT_EQ(GRPC_CHANNEL_IDLE, channel_->GetState(false));
+
+ // Did not ask to connect, no state change.
+ CompletionQueue cq;
+ std::chrono::system_clock::time_point deadline =
+ std::chrono::system_clock::now() + std::chrono::milliseconds(10);
+ channel_->NotifyOnStateChange(GRPC_CHANNEL_IDLE, deadline, &cq, NULL);
+ void* tag;
+ bool ok = true;
+ cq.Next(&tag, &ok);
+ EXPECT_FALSE(ok);
+
+ EXPECT_EQ(GRPC_CHANNEL_IDLE, channel_->GetState(true));
+ EXPECT_TRUE(channel_->WaitForStateChange(
+ GRPC_CHANNEL_IDLE, gpr_inf_future(GPR_CLOCK_REALTIME)));
+ EXPECT_EQ(GRPC_CHANNEL_CONNECTING, channel_->GetState(false));
+}
+
INSTANTIATE_TEST_CASE_P(End2end, End2endTest, ::testing::Values(false, true));
} // namespace testing