1 //
2 //
3 // Copyright 2015 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 //
18
19 #include <grpc/grpc.h>
20 #include <grpc/impl/channel_arg_names.h>
21
22 #include "gmock/gmock.h"
23 #include "gtest/gtest.h"
24 #include "src/core/lib/channel/channel_args.h"
25 #include "src/core/util/time.h"
26 #include "test/core/end2end/end2end_tests.h"
27
28 namespace grpc_core {
29 namespace {
30
CORE_END2END_TEST(RetryHttp2Test,Ping)31 CORE_END2END_TEST(RetryHttp2Test, Ping) {
32 const int kPingCount = 5;
33 grpc_connectivity_state state = GRPC_CHANNEL_IDLE;
34 InitClient(ChannelArgs()
35 .Set(GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA, 0)
36 .Set(GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS, 1));
37 InitServer(ChannelArgs()
38 .Set(GRPC_ARG_HTTP2_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS, 0)
39 .Set(GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS, 1));
40 PingServerFromClient(0);
41 Expect(0, false);
42 Step();
43 // check that we're still in idle, and start connecting
44 EXPECT_EQ(CheckConnectivityState(true), GRPC_CHANNEL_IDLE);
45 // we'll go through some set of transitions (some might be missed), until
46 // READY is reached
47 while (state != GRPC_CHANNEL_READY) {
48 WatchConnectivityState(state, Duration::Seconds(3), 99);
49 Expect(99, true);
50 Step();
51 state = CheckConnectivityState(false);
52 EXPECT_THAT(state,
53 ::testing::AnyOf(GRPC_CHANNEL_READY, GRPC_CHANNEL_CONNECTING,
54 GRPC_CHANNEL_TRANSIENT_FAILURE));
55 }
56 for (int i = 1; i <= kPingCount; i++) {
57 PingServerFromClient(i);
58 Expect(i, true);
59 Step();
60 }
61 ShutdownServerAndNotify(1000);
62 Expect(1000, true);
63 Step();
64 }
65
66 } // namespace
67 } // namespace grpc_core
68