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