Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 0605995 | 2015-02-18 08:34:56 -0800 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -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 <stdio.h> |
| 37 | #include <string.h> |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 38 | |
| 39 | #include <grpc/byte_buffer.h> |
| 40 | #include <grpc/support/alloc.h> |
| 41 | #include <grpc/support/log.h> |
| 42 | #include <grpc/support/time.h> |
| 43 | #include <grpc/support/useful.h> |
| 44 | #include "test/core/end2end/cq_verifier.h" |
| 45 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 46 | enum |
| 47 | { TIMEOUT = 200000 }; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 48 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 49 | static void * |
| 50 | tag (gpr_intptr t) |
| 51 | { |
| 52 | return (void *) t; |
| 53 | } |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 54 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 55 | static grpc_end2end_test_fixture |
| 56 | begin_test (grpc_end2end_test_config config, const char *test_name, grpc_channel_args * client_args, grpc_channel_args * server_args) |
| 57 | { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 58 | grpc_end2end_test_fixture f; |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 59 | gpr_log (GPR_INFO, "%s/%s", test_name, config.name); |
| 60 | f = config.create_fixture (client_args, server_args); |
| 61 | config.init_client (&f, client_args); |
| 62 | config.init_server (&f, server_args); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 63 | return f; |
| 64 | } |
| 65 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 66 | static gpr_timespec |
| 67 | n_seconds_time (int n) |
| 68 | { |
| 69 | return GRPC_TIMEOUT_SECONDS_TO_DEADLINE (n); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 70 | } |
| 71 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 72 | static gpr_timespec |
| 73 | five_seconds_time (void) |
| 74 | { |
| 75 | return n_seconds_time (5); |
| 76 | } |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 77 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 78 | static void |
| 79 | drain_cq (grpc_completion_queue * cq) |
| 80 | { |
Craig Tiller | 64be9f7 | 2015-05-04 14:53:51 -0700 | [diff] [blame] | 81 | grpc_event ev; |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 82 | do |
| 83 | { |
| 84 | ev = grpc_completion_queue_next (cq, five_seconds_time (), NULL); |
| 85 | } |
| 86 | while (ev.type != GRPC_QUEUE_SHUTDOWN); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 87 | } |
| 88 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 89 | static void |
| 90 | shutdown_server (grpc_end2end_test_fixture * f) |
| 91 | { |
| 92 | if (!f->server) |
| 93 | return; |
| 94 | grpc_server_shutdown_and_notify (f->server, f->cq, tag (1000)); |
| 95 | GPR_ASSERT (grpc_completion_queue_pluck (f->cq, tag (1000), GRPC_TIMEOUT_SECONDS_TO_DEADLINE (5), NULL).type == GRPC_OP_COMPLETE); |
| 96 | grpc_server_destroy (f->server); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 97 | f->server = NULL; |
| 98 | } |
| 99 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 100 | static void |
| 101 | shutdown_client (grpc_end2end_test_fixture * f) |
| 102 | { |
| 103 | if (!f->client) |
| 104 | return; |
| 105 | grpc_channel_destroy (f->client); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 106 | f->client = NULL; |
| 107 | } |
| 108 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 109 | static void |
| 110 | end_test (grpc_end2end_test_fixture * f) |
| 111 | { |
| 112 | shutdown_server (f); |
| 113 | shutdown_client (f); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 114 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 115 | grpc_completion_queue_shutdown (f->cq); |
| 116 | drain_cq (f->cq); |
| 117 | grpc_completion_queue_destroy (f->cq); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 118 | } |
| 119 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 120 | static void |
| 121 | simple_request_body (grpc_end2end_test_fixture f) |
| 122 | { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 123 | grpc_call *c; |
| 124 | grpc_call *s; |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 125 | gpr_timespec deadline = five_seconds_time (); |
| 126 | cq_verifier *cqv = cq_verifier_create (f.cq); |
Craig Tiller | 8b1d989 | 2015-04-28 14:28:19 -0700 | [diff] [blame] | 127 | grpc_op ops[6]; |
| 128 | grpc_op *op; |
| 129 | grpc_metadata_array initial_metadata_recv; |
| 130 | grpc_metadata_array trailing_metadata_recv; |
| 131 | grpc_metadata_array request_metadata_recv; |
| 132 | grpc_call_details call_details; |
| 133 | grpc_status_code status; |
Nicolas "Pixel" Noble | 9a123df | 2015-07-29 23:45:08 +0200 | [diff] [blame] | 134 | grpc_call_error error; |
Craig Tiller | 8b1d989 | 2015-04-28 14:28:19 -0700 | [diff] [blame] | 135 | char *details = NULL; |
| 136 | size_t details_capacity = 0; |
| 137 | int was_cancelled = 2; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 138 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 139 | c = grpc_channel_create_call (f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", "foo.test.google.fr:1234", deadline, NULL); |
| 140 | GPR_ASSERT (c); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 141 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 142 | grpc_metadata_array_init (&initial_metadata_recv); |
| 143 | grpc_metadata_array_init (&trailing_metadata_recv); |
| 144 | grpc_metadata_array_init (&request_metadata_recv); |
| 145 | grpc_call_details_init (&call_details); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 146 | |
Craig Tiller | 8b1d989 | 2015-04-28 14:28:19 -0700 | [diff] [blame] | 147 | op = ops; |
| 148 | op->op = GRPC_OP_SEND_INITIAL_METADATA; |
| 149 | op->data.send_initial_metadata.count = 0; |
David Garcia Quintas | 1d5aca5 | 2015-06-14 14:42:04 -0700 | [diff] [blame] | 150 | op->flags = 0; |
Nicolas "Pixel" Noble | 4960516 | 2015-08-01 00:12:01 +0200 | [diff] [blame] | 151 | op->reserved = NULL; |
Craig Tiller | 8b1d989 | 2015-04-28 14:28:19 -0700 | [diff] [blame] | 152 | op++; |
| 153 | op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; |
David Garcia Quintas | 1d5aca5 | 2015-06-14 14:42:04 -0700 | [diff] [blame] | 154 | op->flags = 0; |
Nicolas "Pixel" Noble | 4960516 | 2015-08-01 00:12:01 +0200 | [diff] [blame] | 155 | op->reserved = NULL; |
Craig Tiller | 8b1d989 | 2015-04-28 14:28:19 -0700 | [diff] [blame] | 156 | op++; |
| 157 | op->op = GRPC_OP_RECV_INITIAL_METADATA; |
| 158 | op->data.recv_initial_metadata = &initial_metadata_recv; |
David Garcia Quintas | 1d5aca5 | 2015-06-14 14:42:04 -0700 | [diff] [blame] | 159 | op->flags = 0; |
Nicolas "Pixel" Noble | 4960516 | 2015-08-01 00:12:01 +0200 | [diff] [blame] | 160 | op->reserved = NULL; |
Craig Tiller | 8b1d989 | 2015-04-28 14:28:19 -0700 | [diff] [blame] | 161 | op++; |
| 162 | op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; |
| 163 | op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; |
| 164 | op->data.recv_status_on_client.status = &status; |
| 165 | op->data.recv_status_on_client.status_details = &details; |
| 166 | op->data.recv_status_on_client.status_details_capacity = &details_capacity; |
David Garcia Quintas | 1d5aca5 | 2015-06-14 14:42:04 -0700 | [diff] [blame] | 167 | op->flags = 0; |
Nicolas "Pixel" Noble | 4960516 | 2015-08-01 00:12:01 +0200 | [diff] [blame] | 168 | op->reserved = NULL; |
Craig Tiller | 8b1d989 | 2015-04-28 14:28:19 -0700 | [diff] [blame] | 169 | op++; |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 170 | error = grpc_call_start_batch (c, ops, (size_t) (op - ops), tag (1), NULL); |
| 171 | GPR_ASSERT (GRPC_CALL_OK == error); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 172 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 173 | error = grpc_server_request_call (f.server, &s, &call_details, &request_metadata_recv, f.cq, f.cq, tag (101)); |
| 174 | GPR_ASSERT (GRPC_CALL_OK == error); |
| 175 | cq_expect_completion (cqv, tag (101), 1); |
| 176 | cq_verify (cqv); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 177 | |
Craig Tiller | 8b1d989 | 2015-04-28 14:28:19 -0700 | [diff] [blame] | 178 | op = ops; |
| 179 | op->op = GRPC_OP_SEND_INITIAL_METADATA; |
| 180 | op->data.send_initial_metadata.count = 0; |
David Garcia Quintas | 1d5aca5 | 2015-06-14 14:42:04 -0700 | [diff] [blame] | 181 | op->flags = 0; |
Nicolas "Pixel" Noble | 4960516 | 2015-08-01 00:12:01 +0200 | [diff] [blame] | 182 | op->reserved = NULL; |
Craig Tiller | 8b1d989 | 2015-04-28 14:28:19 -0700 | [diff] [blame] | 183 | op++; |
| 184 | op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; |
| 185 | op->data.send_status_from_server.trailing_metadata_count = 0; |
| 186 | op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; |
| 187 | op->data.send_status_from_server.status_details = "xyz"; |
David Garcia Quintas | 1d5aca5 | 2015-06-14 14:42:04 -0700 | [diff] [blame] | 188 | op->flags = 0; |
Nicolas "Pixel" Noble | 4960516 | 2015-08-01 00:12:01 +0200 | [diff] [blame] | 189 | op->reserved = NULL; |
Craig Tiller | 8b1d989 | 2015-04-28 14:28:19 -0700 | [diff] [blame] | 190 | op++; |
| 191 | op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; |
| 192 | op->data.recv_close_on_server.cancelled = &was_cancelled; |
David Garcia Quintas | 1d5aca5 | 2015-06-14 14:42:04 -0700 | [diff] [blame] | 193 | op->flags = 0; |
Nicolas "Pixel" Noble | 4960516 | 2015-08-01 00:12:01 +0200 | [diff] [blame] | 194 | op->reserved = NULL; |
Craig Tiller | 8b1d989 | 2015-04-28 14:28:19 -0700 | [diff] [blame] | 195 | op++; |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 196 | error = grpc_call_start_batch (s, ops, (size_t) (op - ops), tag (102), NULL); |
| 197 | GPR_ASSERT (GRPC_CALL_OK == error); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 198 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 199 | cq_expect_completion (cqv, tag (102), 1); |
| 200 | cq_expect_completion (cqv, tag (1), 1); |
| 201 | cq_verify (cqv); |
Craig Tiller | 8b1d989 | 2015-04-28 14:28:19 -0700 | [diff] [blame] | 202 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 203 | GPR_ASSERT (status == GRPC_STATUS_UNIMPLEMENTED); |
| 204 | GPR_ASSERT (0 == strcmp (details, "xyz")); |
| 205 | GPR_ASSERT (0 == strcmp (call_details.method, "/foo")); |
| 206 | GPR_ASSERT (0 == strcmp (call_details.host, "foo.test.google.fr:1234")); |
| 207 | GPR_ASSERT (was_cancelled == 1); |
Craig Tiller | 8b1d989 | 2015-04-28 14:28:19 -0700 | [diff] [blame] | 208 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 209 | gpr_free (details); |
| 210 | grpc_metadata_array_destroy (&initial_metadata_recv); |
| 211 | grpc_metadata_array_destroy (&trailing_metadata_recv); |
| 212 | grpc_metadata_array_destroy (&request_metadata_recv); |
| 213 | grpc_call_details_destroy (&call_details); |
Craig Tiller | 8b1d989 | 2015-04-28 14:28:19 -0700 | [diff] [blame] | 214 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 215 | grpc_call_destroy (c); |
| 216 | grpc_call_destroy (s); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 217 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 218 | cq_verifier_destroy (cqv); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 219 | } |
| 220 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 221 | static void |
| 222 | test_max_concurrent_streams (grpc_end2end_test_config config) |
| 223 | { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 224 | grpc_end2end_test_fixture f; |
| 225 | grpc_arg server_arg; |
| 226 | grpc_channel_args server_args; |
| 227 | grpc_call *c1; |
| 228 | grpc_call *c2; |
| 229 | grpc_call *s1; |
| 230 | grpc_call *s2; |
ctiller | 58393c2 | 2015-01-07 14:03:30 -0800 | [diff] [blame] | 231 | int live_call; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 232 | gpr_timespec deadline; |
Craig Tiller | bc0ec33 | 2015-05-11 12:11:32 -0700 | [diff] [blame] | 233 | cq_verifier *cqv; |
Craig Tiller | 64be9f7 | 2015-05-04 14:53:51 -0700 | [diff] [blame] | 234 | grpc_event ev; |
Craig Tiller | 3b05a12 | 2015-04-28 15:14:40 -0700 | [diff] [blame] | 235 | grpc_call_details call_details; |
| 236 | grpc_metadata_array request_metadata_recv; |
| 237 | grpc_metadata_array initial_metadata_recv1; |
| 238 | grpc_metadata_array trailing_metadata_recv1; |
| 239 | grpc_metadata_array initial_metadata_recv2; |
| 240 | grpc_metadata_array trailing_metadata_recv2; |
| 241 | grpc_status_code status1; |
Nicolas "Pixel" Noble | 9a123df | 2015-07-29 23:45:08 +0200 | [diff] [blame] | 242 | grpc_call_error error; |
Craig Tiller | 3b05a12 | 2015-04-28 15:14:40 -0700 | [diff] [blame] | 243 | char *details1 = NULL; |
| 244 | size_t details_capacity1 = 0; |
| 245 | grpc_status_code status2; |
| 246 | char *details2 = NULL; |
| 247 | size_t details_capacity2 = 0; |
Craig Tiller | fe2b835 | 2015-04-28 15:46:50 -0700 | [diff] [blame] | 248 | grpc_op ops[6]; |
| 249 | grpc_op *op; |
| 250 | int was_cancelled; |
Craig Tiller | 4a71600 | 2015-05-11 14:31:58 -0700 | [diff] [blame] | 251 | int got_client_start; |
| 252 | int got_server_start; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 253 | |
| 254 | server_arg.key = GRPC_ARG_MAX_CONCURRENT_STREAMS; |
| 255 | server_arg.type = GRPC_ARG_INTEGER; |
| 256 | server_arg.value.integer = 1; |
| 257 | |
| 258 | server_args.num_args = 1; |
| 259 | server_args.args = &server_arg; |
| 260 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 261 | f = begin_test (config, "test_max_concurrent_streams", NULL, &server_args); |
| 262 | cqv = cq_verifier_create (f.cq); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 263 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 264 | grpc_metadata_array_init (&request_metadata_recv); |
| 265 | grpc_metadata_array_init (&initial_metadata_recv1); |
| 266 | grpc_metadata_array_init (&trailing_metadata_recv1); |
| 267 | grpc_metadata_array_init (&initial_metadata_recv2); |
| 268 | grpc_metadata_array_init (&trailing_metadata_recv2); |
| 269 | grpc_call_details_init (&call_details); |
Craig Tiller | 3b05a12 | 2015-04-28 15:14:40 -0700 | [diff] [blame] | 270 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 271 | /* perform a ping-pong to ensure that settings have had a chance to round |
| 272 | trip */ |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 273 | simple_request_body (f); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 274 | /* perform another one to make sure that the one stream case still works */ |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 275 | simple_request_body (f); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 276 | |
| 277 | /* start two requests - ensuring that the second is not accepted until |
| 278 | the first completes */ |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 279 | deadline = n_seconds_time (1000); |
| 280 | c1 = grpc_channel_create_call (f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/alpha", "foo.test.google.fr:1234", deadline, NULL); |
| 281 | GPR_ASSERT (c1); |
| 282 | c2 = grpc_channel_create_call (f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/beta", "foo.test.google.fr:1234", deadline, NULL); |
| 283 | GPR_ASSERT (c2); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 284 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 285 | GPR_ASSERT (GRPC_CALL_OK == grpc_server_request_call (f.server, &s1, &call_details, &request_metadata_recv, f.cq, f.cq, tag (101))); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 286 | |
Craig Tiller | 3b05a12 | 2015-04-28 15:14:40 -0700 | [diff] [blame] | 287 | op = ops; |
| 288 | op->op = GRPC_OP_SEND_INITIAL_METADATA; |
| 289 | op->data.send_initial_metadata.count = 0; |
David Garcia Quintas | 1d5aca5 | 2015-06-14 14:42:04 -0700 | [diff] [blame] | 290 | op->flags = 0; |
Nicolas "Pixel" Noble | 4960516 | 2015-08-01 00:12:01 +0200 | [diff] [blame] | 291 | op->reserved = NULL; |
Craig Tiller | 3b05a12 | 2015-04-28 15:14:40 -0700 | [diff] [blame] | 292 | op++; |
| 293 | op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; |
David Garcia Quintas | 1d5aca5 | 2015-06-14 14:42:04 -0700 | [diff] [blame] | 294 | op->flags = 0; |
Nicolas "Pixel" Noble | 4960516 | 2015-08-01 00:12:01 +0200 | [diff] [blame] | 295 | op->reserved = NULL; |
Craig Tiller | 3b05a12 | 2015-04-28 15:14:40 -0700 | [diff] [blame] | 296 | op++; |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 297 | error = grpc_call_start_batch (c1, ops, (size_t) (op - ops), tag (301), NULL); |
| 298 | GPR_ASSERT (GRPC_CALL_OK == error); |
Craig Tiller | 3b05a12 | 2015-04-28 15:14:40 -0700 | [diff] [blame] | 299 | |
| 300 | op = ops; |
| 301 | op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; |
Craig Tiller | fe2b835 | 2015-04-28 15:46:50 -0700 | [diff] [blame] | 302 | op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv1; |
| 303 | op->data.recv_status_on_client.status = &status1; |
| 304 | op->data.recv_status_on_client.status_details = &details1; |
| 305 | op->data.recv_status_on_client.status_details_capacity = &details_capacity1; |
David Garcia Quintas | 1d5aca5 | 2015-06-14 14:42:04 -0700 | [diff] [blame] | 306 | op->flags = 0; |
Nicolas "Pixel" Noble | 4960516 | 2015-08-01 00:12:01 +0200 | [diff] [blame] | 307 | op->reserved = NULL; |
Craig Tiller | 3b05a12 | 2015-04-28 15:14:40 -0700 | [diff] [blame] | 308 | op++; |
Craig Tiller | 06eb5ae | 2015-04-30 13:48:58 -0700 | [diff] [blame] | 309 | op->op = GRPC_OP_RECV_INITIAL_METADATA; |
| 310 | op->data.recv_initial_metadata = &initial_metadata_recv1; |
David Garcia Quintas | 1d5aca5 | 2015-06-14 14:42:04 -0700 | [diff] [blame] | 311 | op->flags = 0; |
Nicolas "Pixel" Noble | 4960516 | 2015-08-01 00:12:01 +0200 | [diff] [blame] | 312 | op->reserved = NULL; |
Craig Tiller | 06eb5ae | 2015-04-30 13:48:58 -0700 | [diff] [blame] | 313 | op++; |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 314 | error = grpc_call_start_batch (c1, ops, (size_t) (op - ops), tag (302), NULL); |
| 315 | GPR_ASSERT (GRPC_CALL_OK == error); |
Craig Tiller | 3b05a12 | 2015-04-28 15:14:40 -0700 | [diff] [blame] | 316 | |
| 317 | op = ops; |
| 318 | op->op = GRPC_OP_SEND_INITIAL_METADATA; |
| 319 | op->data.send_initial_metadata.count = 0; |
David Garcia Quintas | 1d5aca5 | 2015-06-14 14:42:04 -0700 | [diff] [blame] | 320 | op->flags = 0; |
Nicolas "Pixel" Noble | 4960516 | 2015-08-01 00:12:01 +0200 | [diff] [blame] | 321 | op->reserved = NULL; |
Craig Tiller | 3b05a12 | 2015-04-28 15:14:40 -0700 | [diff] [blame] | 322 | op++; |
| 323 | op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; |
David Garcia Quintas | 1d5aca5 | 2015-06-14 14:42:04 -0700 | [diff] [blame] | 324 | op->flags = 0; |
Nicolas "Pixel" Noble | 4960516 | 2015-08-01 00:12:01 +0200 | [diff] [blame] | 325 | op->reserved = NULL; |
Craig Tiller | 3b05a12 | 2015-04-28 15:14:40 -0700 | [diff] [blame] | 326 | op++; |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 327 | error = grpc_call_start_batch (c2, ops, (size_t) (op - ops), tag (401), NULL); |
| 328 | GPR_ASSERT (GRPC_CALL_OK == error); |
Craig Tiller | 3b05a12 | 2015-04-28 15:14:40 -0700 | [diff] [blame] | 329 | |
| 330 | op = ops; |
| 331 | op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; |
Craig Tiller | fe2b835 | 2015-04-28 15:46:50 -0700 | [diff] [blame] | 332 | op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv2; |
| 333 | op->data.recv_status_on_client.status = &status2; |
| 334 | op->data.recv_status_on_client.status_details = &details2; |
| 335 | op->data.recv_status_on_client.status_details_capacity = &details_capacity2; |
David Garcia Quintas | 1d5aca5 | 2015-06-14 14:42:04 -0700 | [diff] [blame] | 336 | op->flags = 0; |
Nicolas "Pixel" Noble | 4960516 | 2015-08-01 00:12:01 +0200 | [diff] [blame] | 337 | op->reserved = NULL; |
Craig Tiller | 3b05a12 | 2015-04-28 15:14:40 -0700 | [diff] [blame] | 338 | op++; |
Craig Tiller | 06eb5ae | 2015-04-30 13:48:58 -0700 | [diff] [blame] | 339 | op->op = GRPC_OP_RECV_INITIAL_METADATA; |
| 340 | op->data.recv_initial_metadata = &initial_metadata_recv1; |
David Garcia Quintas | 1d5aca5 | 2015-06-14 14:42:04 -0700 | [diff] [blame] | 341 | op->flags = 0; |
Nicolas "Pixel" Noble | 4960516 | 2015-08-01 00:12:01 +0200 | [diff] [blame] | 342 | op->reserved = NULL; |
Craig Tiller | 06eb5ae | 2015-04-30 13:48:58 -0700 | [diff] [blame] | 343 | op++; |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 344 | error = grpc_call_start_batch (c2, ops, (size_t) (op - ops), tag (402), NULL); |
| 345 | GPR_ASSERT (GRPC_CALL_OK == error); |
Craig Tiller | 80fa15c | 2015-01-13 16:10:49 -0800 | [diff] [blame] | 346 | |
Craig Tiller | 4a71600 | 2015-05-11 14:31:58 -0700 | [diff] [blame] | 347 | got_client_start = 0; |
| 348 | got_server_start = 0; |
Craig Tiller | a0a6b12 | 2015-05-12 14:42:27 -0700 | [diff] [blame] | 349 | live_call = -1; |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 350 | while (!got_client_start || !got_server_start) |
| 351 | { |
| 352 | ev = grpc_completion_queue_next (f.cq, GRPC_TIMEOUT_SECONDS_TO_DEADLINE (3), NULL); |
| 353 | GPR_ASSERT (ev.type == GRPC_OP_COMPLETE); |
| 354 | GPR_ASSERT (ev.success); |
| 355 | if (ev.tag == tag (101)) |
| 356 | { |
| 357 | GPR_ASSERT (!got_server_start); |
| 358 | got_server_start = 1; |
| 359 | } |
| 360 | else |
| 361 | { |
| 362 | GPR_ASSERT (!got_client_start); |
| 363 | GPR_ASSERT (ev.tag == tag (301) || ev.tag == tag (401)); |
| 364 | /* The /alpha or /beta calls started above could be invoked (but NOT |
| 365 | * both); |
| 366 | * check this here */ |
| 367 | /* We'll get tag 303 or 403, we want 300, 400 */ |
| 368 | live_call = ((int) (gpr_intptr) ev.tag) - 1; |
| 369 | got_client_start = 1; |
| 370 | } |
Craig Tiller | 4a71600 | 2015-05-11 14:31:58 -0700 | [diff] [blame] | 371 | } |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 372 | GPR_ASSERT (live_call == 300 || live_call == 400); |
ctiller | 58393c2 | 2015-01-07 14:03:30 -0800 | [diff] [blame] | 373 | |
Craig Tiller | 3b05a12 | 2015-04-28 15:14:40 -0700 | [diff] [blame] | 374 | op = ops; |
| 375 | op->op = GRPC_OP_SEND_INITIAL_METADATA; |
| 376 | op->data.send_initial_metadata.count = 0; |
David Garcia Quintas | 1d5aca5 | 2015-06-14 14:42:04 -0700 | [diff] [blame] | 377 | op->flags = 0; |
Nicolas "Pixel" Noble | 4960516 | 2015-08-01 00:12:01 +0200 | [diff] [blame] | 378 | op->reserved = NULL; |
Craig Tiller | 3b05a12 | 2015-04-28 15:14:40 -0700 | [diff] [blame] | 379 | op++; |
| 380 | op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; |
| 381 | op->data.recv_close_on_server.cancelled = &was_cancelled; |
David Garcia Quintas | 1d5aca5 | 2015-06-14 14:42:04 -0700 | [diff] [blame] | 382 | op->flags = 0; |
Nicolas "Pixel" Noble | 4960516 | 2015-08-01 00:12:01 +0200 | [diff] [blame] | 383 | op->reserved = NULL; |
Craig Tiller | 3b05a12 | 2015-04-28 15:14:40 -0700 | [diff] [blame] | 384 | op++; |
Craig Tiller | 3b05a12 | 2015-04-28 15:14:40 -0700 | [diff] [blame] | 385 | op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; |
| 386 | op->data.send_status_from_server.trailing_metadata_count = 0; |
| 387 | op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; |
| 388 | op->data.send_status_from_server.status_details = "xyz"; |
David Garcia Quintas | 1d5aca5 | 2015-06-14 14:42:04 -0700 | [diff] [blame] | 389 | op->flags = 0; |
Nicolas "Pixel" Noble | 4960516 | 2015-08-01 00:12:01 +0200 | [diff] [blame] | 390 | op->reserved = NULL; |
Craig Tiller | 3b05a12 | 2015-04-28 15:14:40 -0700 | [diff] [blame] | 391 | op++; |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 392 | error = grpc_call_start_batch (s1, ops, (size_t) (op - ops), tag (102), NULL); |
| 393 | GPR_ASSERT (GRPC_CALL_OK == error); |
Craig Tiller | 3b05a12 | 2015-04-28 15:14:40 -0700 | [diff] [blame] | 394 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 395 | cq_expect_completion (cqv, tag (102), 1); |
| 396 | cq_expect_completion (cqv, tag (live_call + 2), 1); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 397 | /* first request is finished, we should be able to start the second */ |
Craig Tiller | bf44493 | 2015-01-13 17:13:08 -0800 | [diff] [blame] | 398 | live_call = (live_call == 300) ? 400 : 300; |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 399 | cq_expect_completion (cqv, tag (live_call + 1), 1); |
| 400 | cq_verify (cqv); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 401 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 402 | GPR_ASSERT (GRPC_CALL_OK == grpc_server_request_call (f.server, &s2, &call_details, &request_metadata_recv, f.cq, f.cq, tag (201))); |
| 403 | cq_expect_completion (cqv, tag (201), 1); |
| 404 | cq_verify (cqv); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 405 | |
Craig Tiller | 3b05a12 | 2015-04-28 15:14:40 -0700 | [diff] [blame] | 406 | op = ops; |
| 407 | op->op = GRPC_OP_SEND_INITIAL_METADATA; |
| 408 | op->data.send_initial_metadata.count = 0; |
David Garcia Quintas | 1d5aca5 | 2015-06-14 14:42:04 -0700 | [diff] [blame] | 409 | op->flags = 0; |
Nicolas "Pixel" Noble | 4960516 | 2015-08-01 00:12:01 +0200 | [diff] [blame] | 410 | op->reserved = NULL; |
Craig Tiller | 3b05a12 | 2015-04-28 15:14:40 -0700 | [diff] [blame] | 411 | op++; |
| 412 | op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; |
| 413 | op->data.recv_close_on_server.cancelled = &was_cancelled; |
David Garcia Quintas | 1d5aca5 | 2015-06-14 14:42:04 -0700 | [diff] [blame] | 414 | op->flags = 0; |
Nicolas "Pixel" Noble | 4960516 | 2015-08-01 00:12:01 +0200 | [diff] [blame] | 415 | op->reserved = NULL; |
Craig Tiller | 3b05a12 | 2015-04-28 15:14:40 -0700 | [diff] [blame] | 416 | op++; |
Craig Tiller | fe2b835 | 2015-04-28 15:46:50 -0700 | [diff] [blame] | 417 | op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; |
| 418 | op->data.send_status_from_server.trailing_metadata_count = 0; |
| 419 | op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; |
| 420 | op->data.send_status_from_server.status_details = "xyz"; |
David Garcia Quintas | 1d5aca5 | 2015-06-14 14:42:04 -0700 | [diff] [blame] | 421 | op->flags = 0; |
Nicolas "Pixel" Noble | 4960516 | 2015-08-01 00:12:01 +0200 | [diff] [blame] | 422 | op->reserved = NULL; |
Craig Tiller | fe2b835 | 2015-04-28 15:46:50 -0700 | [diff] [blame] | 423 | op++; |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 424 | error = grpc_call_start_batch (s2, ops, (size_t) (op - ops), tag (202), NULL); |
| 425 | GPR_ASSERT (GRPC_CALL_OK == error); |
Craig Tiller | 06eb5ae | 2015-04-30 13:48:58 -0700 | [diff] [blame] | 426 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 427 | cq_expect_completion (cqv, tag (live_call + 2), 1); |
| 428 | cq_expect_completion (cqv, tag (202), 1); |
| 429 | cq_verify (cqv); |
Craig Tiller | fe2b835 | 2015-04-28 15:46:50 -0700 | [diff] [blame] | 430 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 431 | cq_verifier_destroy (cqv); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 432 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 433 | grpc_call_destroy (c1); |
| 434 | grpc_call_destroy (s1); |
| 435 | grpc_call_destroy (c2); |
| 436 | grpc_call_destroy (s2); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 437 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 438 | gpr_free (details1); |
| 439 | gpr_free (details2); |
| 440 | grpc_metadata_array_destroy (&initial_metadata_recv1); |
| 441 | grpc_metadata_array_destroy (&trailing_metadata_recv1); |
| 442 | grpc_metadata_array_destroy (&initial_metadata_recv2); |
| 443 | grpc_metadata_array_destroy (&trailing_metadata_recv2); |
| 444 | grpc_metadata_array_destroy (&request_metadata_recv); |
| 445 | grpc_call_details_destroy (&call_details); |
Craig Tiller | 5fe7e5d | 2015-05-01 10:52:35 -0700 | [diff] [blame] | 446 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 447 | end_test (&f); |
| 448 | config.tear_down_data (&f); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 449 | } |
| 450 | |
Craig Tiller | 45724b3 | 2015-09-22 10:42:19 -0700 | [diff] [blame] | 451 | void |
| 452 | grpc_end2end_tests (grpc_end2end_test_config config) |
| 453 | { |
| 454 | test_max_concurrent_streams (config); |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 455 | } |