ping.cc
Go to the documentation of this file.
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/support/log.h>
20 #include <grpc/support/sync.h>
21 #include <grpc/support/time.h>
22 
28 
29 #define PING_NUM 5
30 
31 static void* tag(intptr_t t) { return reinterpret_cast<void*>(t); }
32 
34  int min_time_between_pings_ms) {
35  grpc_end2end_test_fixture f = config.create_fixture(nullptr, nullptr);
36  cq_verifier* cqv = cq_verifier_create(f.cq);
38  int i;
39 
40  grpc_arg client_a[] = {
42  const_cast<char*>(GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA), 0),
44  const_cast<char*>(GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS), 1)};
45  grpc_arg server_a[] = {
47  const_cast<char*>(
49  0),
51  const_cast<char*>(GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS), 1)};
52  grpc_channel_args client_args = {GPR_ARRAY_SIZE(client_a), client_a};
53  grpc_channel_args server_args = {GPR_ARRAY_SIZE(server_a), server_a};
54 
55  config.init_client(&f, &client_args);
56  config.init_server(&f, &server_args);
57 
58  grpc_channel_ping(f.client, f.cq, tag(0), nullptr);
59  CQ_EXPECT_COMPLETION(cqv, tag(0), 0);
60 
61  /* check that we're still in idle, and start connecting */
64  /* we'll go through some set of transitions (some might be missed), until
65  READY is reached */
66  while (state != GRPC_CHANNEL_READY) {
68  f.client, state,
70  gpr_time_from_millis(min_time_between_pings_ms * PING_NUM,
71  GPR_TIMESPAN)),
72  f.cq, tag(99));
73  CQ_EXPECT_COMPLETION(cqv, tag(99), 1);
74  cq_verify(cqv);
79  }
80 
81  for (i = 1; i <= PING_NUM; i++) {
82  grpc_channel_ping(f.client, f.cq, tag(i), nullptr);
83  CQ_EXPECT_COMPLETION(cqv, tag(i), 1);
84  cq_verify(cqv);
85  }
86 
87  grpc_server_shutdown_and_notify(f.server, f.cq, tag(0xdead));
88  CQ_EXPECT_COMPLETION(cqv, tag(0xdead), 1);
89  cq_verify(cqv);
90 
91  /* cleanup server */
92  grpc_server_destroy(f.server);
93 
94  grpc_channel_destroy(f.client);
97 
98  config.tear_down_data(&f);
99 
100  cq_verifier_destroy(cqv);
101 }
102 
105  test_ping(config, 0);
106  test_ping(config, 100);
107 }
108 
109 void ping_pre_init(void) {}
grpc_arg
Definition: grpc_types.h:103
GPR_TIMESPAN
@ GPR_TIMESPAN
Definition: gpr_types.h:45
GRPC_CHANNEL_READY
@ GRPC_CHANNEL_READY
Definition: include/grpc/impl/codegen/connectivity_state.h:36
grpc_timeout_seconds_to_deadline
gpr_timespec grpc_timeout_seconds_to_deadline(int64_t time_s)
Definition: test/core/util/test_config.cc:81
log.h
grpc_channel_check_connectivity_state
GRPCAPI grpc_connectivity_state grpc_channel_check_connectivity_state(grpc_channel *channel, int try_to_connect)
Definition: channel_connectivity.cc:56
grpc_channel_ping
void grpc_channel_ping(grpc_channel *channel, grpc_completion_queue *cq, void *tag, void *reserved)
Definition: channel_ping.cc:52
useful.h
GRPC_CHANNEL_TRANSIENT_FAILURE
@ GRPC_CHANNEL_TRANSIENT_FAILURE
Definition: include/grpc/impl/codegen/connectivity_state.h:38
time.h
grpc_end2end_test_config
Definition: end2end_tests.h:53
grpc_channel_args
Definition: grpc_types.h:132
grpc_connectivity_state
grpc_connectivity_state
Definition: include/grpc/impl/codegen/connectivity_state.h:30
grpc_end2end_test_fixture
Definition: end2end_tests.h:46
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION
#define FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION
Definition: end2end_tests.h:28
autogen_x86imm.f
f
Definition: autogen_x86imm.py:9
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
cq_verifier_destroy
void cq_verifier_destroy(cq_verifier *v)
Definition: cq_verifier.cc:92
ping_pre_init
void ping_pre_init(void)
Definition: ping.cc:109
tag
static void * tag(intptr_t t)
Definition: ping.cc:31
GRPC_CHANNEL_IDLE
@ GRPC_CHANNEL_IDLE
Definition: include/grpc/impl/codegen/connectivity_state.h:32
cq_verifier_create
cq_verifier * cq_verifier_create(grpc_completion_queue *cq)
Definition: cq_verifier.cc:86
intptr_t
_W64 signed int intptr_t
Definition: stdint-msvc2008.h:118
GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA
#define GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA
Definition: grpc_types.h:226
cq_verifier
Definition: cq_verifier.cc:76
grpc_server_destroy
GRPCAPI void grpc_server_destroy(grpc_server *server)
Definition: src/core/lib/surface/server.cc:1519
CQ_EXPECT_COMPLETION
#define CQ_EXPECT_COMPLETION(v, tag, success)
Definition: cq_verifier.h:58
end2end_tests.h
test_ping
static void test_ping(grpc_end2end_test_config config, int min_time_between_pings_ms)
Definition: ping.cc:33
GRPC_CHANNEL_CONNECTING
@ GRPC_CHANNEL_CONNECTING
Definition: include/grpc/impl/codegen/connectivity_state.h:34
GPR_ARRAY_SIZE
#define GPR_ARRAY_SIZE(array)
Definition: useful.h:129
grpc_channel_arg_integer_create
grpc_arg grpc_channel_arg_integer_create(char *name, int value)
Definition: channel_args.cc:484
cq_verifier.h
gpr_time_add
GPRAPI gpr_timespec gpr_time_add(gpr_timespec a, gpr_timespec b)
Definition: src/core/lib/gpr/time.cc:135
ping
void ping(grpc_end2end_test_config config)
Definition: ping.cc:103
grpc_completion_queue_destroy
GRPCAPI void grpc_completion_queue_destroy(grpc_completion_queue *cq)
Definition: completion_queue.cc:1424
grpc_server_shutdown_and_notify
GRPCAPI void grpc_server_shutdown_and_notify(grpc_server *server, grpc_completion_queue *cq, void *tag)
Definition: src/core/lib/surface/server.cc:1503
cq_verify
void cq_verify(cq_verifier *v, int timeout_sec)
Definition: cq_verifier.cc:268
grpc_completion_queue_shutdown
GRPCAPI void grpc_completion_queue_shutdown(grpc_completion_queue *cq)
Definition: completion_queue.cc:1416
grpc_channel_destroy
GRPCAPI void grpc_channel_destroy(grpc_channel *channel)
Definition: channel.cc:437
state
Definition: bloaty/third_party/zlib/contrib/blast/blast.c:41
config_s
Definition: bloaty/third_party/zlib/deflate.c:120
gpr_time_from_millis
GPRAPI gpr_timespec gpr_time_from_millis(int64_t ms, gpr_clock_type clock_type)
Definition: src/core/lib/gpr/time.cc:119
PING_NUM
#define PING_NUM
Definition: ping.cc:29
channel_args.h
grpc_channel_watch_connectivity_state
GRPCAPI void grpc_channel_watch_connectivity_state(grpc_channel *channel, grpc_connectivity_state last_observed_state, gpr_timespec deadline, grpc_completion_queue *cq, void *tag)
Definition: channel_connectivity.cc:227
GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS
#define GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS
Definition: grpc_types.h:247
GRPC_ARG_HTTP2_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS
#define GRPC_ARG_HTTP2_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS
Definition: grpc_types.h:219
sync.h
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
channel.h


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:43