Craig Tiller | 26dab31 | 2015-12-07 14:43:47 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Craig Tiller | 26dab31 | 2015-12-07 14:43:47 -0800 | [diff] [blame] | 4 | * 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 Tiller | 7536af0 | 2015-12-22 13:49:30 -0800 | [diff] [blame] | 43 | static void *tag(intptr_t t) { return (void *)t; } |
Craig Tiller | 26dab31 | 2015-12-07 14:43:47 -0800 | [diff] [blame] | 44 | |
| 45 | static 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 Tiller | 28bf891 | 2015-12-07 16:07:04 -0800 | [diff] [blame] | 48 | grpc_connectivity_state state = GRPC_CHANNEL_IDLE; |
Craig Tiller | 26dab31 | 2015-12-07 14:43:47 -0800 | [diff] [blame] | 49 | int i; |
| 50 | |
Mark D. Roth | e127a39 | 2016-10-27 08:27:15 -0700 | [diff] [blame] | 51 | config.init_client(&f, NULL); |
Craig Tiller | 26dab31 | 2015-12-07 14:43:47 -0800 | [diff] [blame] | 52 | config.init_server(&f, NULL); |
| 53 | |
Craig Tiller | 28bf891 | 2015-12-07 16:07:04 -0800 | [diff] [blame] | 54 | grpc_channel_ping(f.client, f.cq, tag(0), NULL); |
Mark D. Roth | 7187ab9 | 2016-08-24 13:49:22 -0700 | [diff] [blame] | 55 | CQ_EXPECT_COMPLETION(cqv, tag(0), 0); |
Craig Tiller | 28bf891 | 2015-12-07 16:07:04 -0800 | [diff] [blame] | 56 | |
| 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. Roth | 7187ab9 | 2016-08-24 13:49:22 -0700 | [diff] [blame] | 65 | CQ_EXPECT_COMPLETION(cqv, tag(99), 1); |
Craig Tiller | 28bf891 | 2015-12-07 16:07:04 -0800 | [diff] [blame] | 66 | 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 Tiller | 26dab31 | 2015-12-07 14:43:47 -0800 | [diff] [blame] | 73 | for (i = 1; i <= 5; i++) { |
| 74 | grpc_channel_ping(f.client, f.cq, tag(i), NULL); |
Mark D. Roth | 7187ab9 | 2016-08-24 13:49:22 -0700 | [diff] [blame] | 75 | CQ_EXPECT_COMPLETION(cqv, tag(i), 1); |
Craig Tiller | 26dab31 | 2015-12-07 14:43:47 -0800 | [diff] [blame] | 76 | cq_verify(cqv); |
| 77 | } |
| 78 | |
| 79 | grpc_server_shutdown_and_notify(f.server, f.cq, tag(0xdead)); |
Mark D. Roth | 7187ab9 | 2016-08-24 13:49:22 -0700 | [diff] [blame] | 80 | CQ_EXPECT_COMPLETION(cqv, tag(0xdead), 1); |
Craig Tiller | 26dab31 | 2015-12-07 14:43:47 -0800 | [diff] [blame] | 81 | 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 Tiller | 521423c | 2016-02-22 22:22:22 -0800 | [diff] [blame] | 94 | void ping(grpc_end2end_test_config config) { |
Craig Tiller | 26dab31 | 2015-12-07 14:43:47 -0800 | [diff] [blame] | 95 | GPR_ASSERT(config.feature_mask & FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION); |
| 96 | test_ping(config); |
| 97 | } |
Craig Tiller | 9e9edbc | 2016-04-04 10:38:49 -0700 | [diff] [blame] | 98 | |
| 99 | void ping_pre_init(void) {} |