OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * |
| 3 * Copyright 2015-2016, Google Inc. |
| 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 |
| 43 static void *tag(intptr_t t) { return (void *)t; } |
| 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); |
| 48 grpc_connectivity_state state = GRPC_CHANNEL_IDLE; |
| 49 int i; |
| 50 |
| 51 config.init_client(&f, NULL); |
| 52 config.init_server(&f, NULL); |
| 53 |
| 54 grpc_channel_ping(f.client, f.cq, tag(0), NULL); |
| 55 cq_expect_completion(cqv, tag(0), 0); |
| 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)); |
| 65 cq_expect_completion(cqv, tag(99), 1); |
| 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 |
| 73 for (i = 1; i <= 5; i++) { |
| 74 grpc_channel_ping(f.client, f.cq, tag(i), NULL); |
| 75 cq_expect_completion(cqv, tag(i), 1); |
| 76 cq_verify(cqv); |
| 77 } |
| 78 |
| 79 grpc_server_shutdown_and_notify(f.server, f.cq, tag(0xdead)); |
| 80 cq_expect_completion(cqv, tag(0xdead), 1); |
| 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 |
| 94 void ping(grpc_end2end_test_config config) { |
| 95 GPR_ASSERT(config.feature_mask & FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION); |
| 96 test_ping(config); |
| 97 } |
OLD | NEW |