xref: /aosp_15_r20/external/grpc-grpc/test/core/end2end/tests/ping.cc (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
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 "gmock/gmock.h"
20 #include "gtest/gtest.h"
21 
22 #include <grpc/grpc.h>
23 #include <grpc/impl/channel_arg_names.h>
24 
25 #include "src/core/lib/channel/channel_args.h"
26 #include "src/core/lib/gprpp/time.h"
27 #include "test/core/end2end/end2end_tests.h"
28 
29 namespace grpc_core {
30 namespace {
31 
CORE_END2END_TEST(RetryHttp2Test,Ping)32 CORE_END2END_TEST(RetryHttp2Test, Ping) {
33   const int kPingCount = 5;
34   grpc_connectivity_state state = GRPC_CHANNEL_IDLE;
35   InitClient(ChannelArgs()
36                  .Set(GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA, 0)
37                  .Set(GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS, 1));
38   InitServer(ChannelArgs()
39                  .Set(GRPC_ARG_HTTP2_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS, 0)
40                  .Set(GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS, 1));
41   PingServerFromClient(0);
42   Expect(0, false);
43   Step();
44   // check that we're still in idle, and start connecting
45   EXPECT_EQ(CheckConnectivityState(true), GRPC_CHANNEL_IDLE);
46   // we'll go through some set of transitions (some might be missed), until
47   // READY is reached
48   while (state != GRPC_CHANNEL_READY) {
49     WatchConnectivityState(state, Duration::Seconds(3), 99);
50     Expect(99, true);
51     Step();
52     state = CheckConnectivityState(false);
53     EXPECT_THAT(state,
54                 ::testing::AnyOf(GRPC_CHANNEL_READY, GRPC_CHANNEL_CONNECTING,
55                                  GRPC_CHANNEL_TRANSIENT_FAILURE));
56   }
57   for (int i = 1; i <= kPingCount; i++) {
58     PingServerFromClient(i);
59     Expect(i, true);
60     Step();
61   }
62   ShutdownServerAndNotify(1000);
63   Expect(1000, true);
64   Step();
65 }
66 
67 }  // namespace
68 }  // namespace grpc_core
69