blob: 5e5169dedcec31b7f32032be47a3a53d36ccf3a8 [file] [log] [blame]
Craig Tiller26dab312015-12-07 14:43:47 -08001/*
2 *
Craig Tiller6169d5f2016-03-31 07:46:18 -07003 * Copyright 2015, Google Inc.
Craig Tiller26dab312015-12-07 14:43:47 -08004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34#include "test/core/end2end/end2end_tests.h"
35
36#include <grpc/support/log.h>
37#include <grpc/support/sync.h>
38#include <grpc/support/thd.h>
39#include <grpc/support/time.h>
40
41#include "test/core/end2end/cq_verifier.h"
42
Craig Tiller7536af02015-12-22 13:49:30 -080043static void *tag(intptr_t t) { return (void *)t; }
Craig Tiller26dab312015-12-07 14:43:47 -080044
45static void test_ping(grpc_end2end_test_config config) {
46 grpc_end2end_test_fixture f = config.create_fixture(NULL, NULL);
47 cq_verifier *cqv = cq_verifier_create(f.cq);
Craig Tiller28bf8912015-12-07 16:07:04 -080048 grpc_connectivity_state state = GRPC_CHANNEL_IDLE;
Craig Tiller26dab312015-12-07 14:43:47 -080049 int i;
50
Mark D. Rothe127a392016-10-27 08:27:15 -070051 config.init_client(&f, NULL);
Craig Tiller26dab312015-12-07 14:43:47 -080052 config.init_server(&f, NULL);
53
Craig Tiller28bf8912015-12-07 16:07:04 -080054 grpc_channel_ping(f.client, f.cq, tag(0), NULL);
Mark D. Roth7187ab92016-08-24 13:49:22 -070055 CQ_EXPECT_COMPLETION(cqv, tag(0), 0);
Craig Tiller28bf8912015-12-07 16:07:04 -080056
57 /* check that we're still in idle, and start connecting */
58 GPR_ASSERT(grpc_channel_check_connectivity_state(f.client, 1) ==
59 GRPC_CHANNEL_IDLE);
60 /* we'll go through some set of transitions (some might be missed), until
61 READY is reached */
62 while (state != GRPC_CHANNEL_READY) {
63 grpc_channel_watch_connectivity_state(
64 f.client, state, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(3), f.cq, tag(99));
Mark D. Roth7187ab92016-08-24 13:49:22 -070065 CQ_EXPECT_COMPLETION(cqv, tag(99), 1);
Craig Tiller28bf8912015-12-07 16:07:04 -080066 cq_verify(cqv);
67 state = grpc_channel_check_connectivity_state(f.client, 0);
68 GPR_ASSERT(state == GRPC_CHANNEL_READY ||
69 state == GRPC_CHANNEL_CONNECTING ||
70 state == GRPC_CHANNEL_TRANSIENT_FAILURE);
71 }
72
Craig Tiller26dab312015-12-07 14:43:47 -080073 for (i = 1; i <= 5; i++) {
74 grpc_channel_ping(f.client, f.cq, tag(i), NULL);
Mark D. Roth7187ab92016-08-24 13:49:22 -070075 CQ_EXPECT_COMPLETION(cqv, tag(i), 1);
Craig Tiller26dab312015-12-07 14:43:47 -080076 cq_verify(cqv);
77 }
78
79 grpc_server_shutdown_and_notify(f.server, f.cq, tag(0xdead));
Mark D. Roth7187ab92016-08-24 13:49:22 -070080 CQ_EXPECT_COMPLETION(cqv, tag(0xdead), 1);
Craig Tiller26dab312015-12-07 14:43:47 -080081 cq_verify(cqv);
82
83 /* cleanup server */
84 grpc_server_destroy(f.server);
85
86 grpc_channel_destroy(f.client);
87 grpc_completion_queue_shutdown(f.cq);
88 grpc_completion_queue_destroy(f.cq);
89 config.tear_down_data(&f);
90
91 cq_verifier_destroy(cqv);
92}
93
Craig Tiller521423c2016-02-22 22:22:22 -080094void ping(grpc_end2end_test_config config) {
Craig Tiller26dab312015-12-07 14:43:47 -080095 GPR_ASSERT(config.feature_mask & FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION);
96 test_ping(config);
97}
Craig Tiller9e9edbc2016-04-04 10:38:49 -070098
99void ping_pre_init(void) {}