blob: 87eb4dd451ea297d660b9e3e65c16b9040e31d3b [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
Craig Tiller06059952015-02-18 08:34:56 -08003 * Copyright 2015, Google Inc.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -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 <stdio.h>
37#include <string.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080038
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 Tillera82950e2015-09-22 12:33:20 -070046enum { TIMEOUT = 200000 };
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080047
Craig Tillera82950e2015-09-22 12:33:20 -070048static void *tag(gpr_intptr t) { return (void *)t; }
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080049
Craig Tillera82950e2015-09-22 12:33:20 -070050static 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) {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080054 grpc_end2end_test_fixture f;
Craig Tillera82950e2015-09-22 12:33:20 -070055 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);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080059 return f;
60}
61
Craig Tillera82950e2015-09-22 12:33:20 -070062static gpr_timespec n_seconds_time(int n) {
63 return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(n);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080064}
65
Craig Tillera82950e2015-09-22 12:33:20 -070066static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080067
Craig Tillera82950e2015-09-22 12:33:20 -070068static void drain_cq(grpc_completion_queue *cq) {
Craig Tiller64be9f72015-05-04 14:53:51 -070069 grpc_event ev;
Craig Tillera82950e2015-09-22 12:33:20 -070070 do {
71 ev = grpc_completion_queue_next(cq, five_seconds_time(), NULL);
72 } while (ev.type != GRPC_QUEUE_SHUTDOWN);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080073}
74
Craig Tillera82950e2015-09-22 12:33:20 -070075static void shutdown_server(grpc_end2end_test_fixture *f) {
76 if (!f->server) return;
77 grpc_server_shutdown_and_notify(f->server, f->cq, tag(1000));
78 GPR_ASSERT(grpc_completion_queue_pluck(
79 f->cq, tag(1000), GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5), NULL)
80 .type == GRPC_OP_COMPLETE);
81 grpc_server_destroy(f->server);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080082 f->server = NULL;
83}
84
Craig Tillera82950e2015-09-22 12:33:20 -070085static void shutdown_client(grpc_end2end_test_fixture *f) {
86 if (!f->client) return;
87 grpc_channel_destroy(f->client);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080088 f->client = NULL;
89}
90
Craig Tillera82950e2015-09-22 12:33:20 -070091static void end_test(grpc_end2end_test_fixture *f) {
92 shutdown_server(f);
93 shutdown_client(f);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080094
Craig Tillera82950e2015-09-22 12:33:20 -070095 grpc_completion_queue_shutdown(f->cq);
96 drain_cq(f->cq);
97 grpc_completion_queue_destroy(f->cq);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080098}
99
Craig Tillera82950e2015-09-22 12:33:20 -0700100static void simple_request_body(grpc_end2end_test_fixture f) {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800101 grpc_call *c;
102 grpc_call *s;
Craig Tillera82950e2015-09-22 12:33:20 -0700103 gpr_timespec deadline = five_seconds_time();
104 cq_verifier *cqv = cq_verifier_create(f.cq);
Craig Tiller8b1d9892015-04-28 14:28:19 -0700105 grpc_op ops[6];
106 grpc_op *op;
107 grpc_metadata_array initial_metadata_recv;
108 grpc_metadata_array trailing_metadata_recv;
109 grpc_metadata_array request_metadata_recv;
110 grpc_call_details call_details;
111 grpc_status_code status;
Nicolas "Pixel" Noble9a123df2015-07-29 23:45:08 +0200112 grpc_call_error error;
Craig Tiller8b1d9892015-04-28 14:28:19 -0700113 char *details = NULL;
114 size_t details_capacity = 0;
115 int was_cancelled = 2;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800116
Craig Tillera82950e2015-09-22 12:33:20 -0700117 c = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq,
118 "/foo", "foo.test.google.fr:1234", deadline,
119 NULL);
120 GPR_ASSERT(c);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800121
Craig Tillera82950e2015-09-22 12:33:20 -0700122 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 Nobleb7ebd3b2014-11-26 16:33:03 -0800126
Craig Tiller8b1d9892015-04-28 14:28:19 -0700127 op = ops;
128 op->op = GRPC_OP_SEND_INITIAL_METADATA;
129 op->data.send_initial_metadata.count = 0;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700130 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200131 op->reserved = NULL;
Craig Tiller8b1d9892015-04-28 14:28:19 -0700132 op++;
133 op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700134 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200135 op->reserved = NULL;
Craig Tiller8b1d9892015-04-28 14:28:19 -0700136 op++;
137 op->op = GRPC_OP_RECV_INITIAL_METADATA;
138 op->data.recv_initial_metadata = &initial_metadata_recv;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700139 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200140 op->reserved = NULL;
Craig Tiller8b1d9892015-04-28 14:28:19 -0700141 op++;
142 op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
143 op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
144 op->data.recv_status_on_client.status = &status;
145 op->data.recv_status_on_client.status_details = &details;
146 op->data.recv_status_on_client.status_details_capacity = &details_capacity;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700147 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200148 op->reserved = NULL;
Craig Tiller8b1d9892015-04-28 14:28:19 -0700149 op++;
Craig Tillera82950e2015-09-22 12:33:20 -0700150 error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
151 GPR_ASSERT(GRPC_CALL_OK == error);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800152
Craig Tillera82950e2015-09-22 12:33:20 -0700153 error =
154 grpc_server_request_call(f.server, &s, &call_details,
155 &request_metadata_recv, f.cq, f.cq, tag(101));
156 GPR_ASSERT(GRPC_CALL_OK == error);
157 cq_expect_completion(cqv, tag(101), 1);
158 cq_verify(cqv);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800159
Craig Tiller8b1d9892015-04-28 14:28:19 -0700160 op = ops;
161 op->op = GRPC_OP_SEND_INITIAL_METADATA;
162 op->data.send_initial_metadata.count = 0;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700163 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200164 op->reserved = NULL;
Craig Tiller8b1d9892015-04-28 14:28:19 -0700165 op++;
166 op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
167 op->data.send_status_from_server.trailing_metadata_count = 0;
168 op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED;
169 op->data.send_status_from_server.status_details = "xyz";
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700170 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200171 op->reserved = NULL;
Craig Tiller8b1d9892015-04-28 14:28:19 -0700172 op++;
173 op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
174 op->data.recv_close_on_server.cancelled = &was_cancelled;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700175 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200176 op->reserved = NULL;
Craig Tiller8b1d9892015-04-28 14:28:19 -0700177 op++;
Craig Tillera82950e2015-09-22 12:33:20 -0700178 error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL);
179 GPR_ASSERT(GRPC_CALL_OK == error);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800180
Craig Tillera82950e2015-09-22 12:33:20 -0700181 cq_expect_completion(cqv, tag(102), 1);
182 cq_expect_completion(cqv, tag(1), 1);
183 cq_verify(cqv);
Craig Tiller8b1d9892015-04-28 14:28:19 -0700184
Craig Tillera82950e2015-09-22 12:33:20 -0700185 GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
186 GPR_ASSERT(0 == strcmp(details, "xyz"));
187 GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
188 GPR_ASSERT(0 == strcmp(call_details.host, "foo.test.google.fr:1234"));
189 GPR_ASSERT(was_cancelled == 1);
Craig Tiller8b1d9892015-04-28 14:28:19 -0700190
Craig Tillera82950e2015-09-22 12:33:20 -0700191 gpr_free(details);
192 grpc_metadata_array_destroy(&initial_metadata_recv);
193 grpc_metadata_array_destroy(&trailing_metadata_recv);
194 grpc_metadata_array_destroy(&request_metadata_recv);
195 grpc_call_details_destroy(&call_details);
Craig Tiller8b1d9892015-04-28 14:28:19 -0700196
Craig Tillera82950e2015-09-22 12:33:20 -0700197 grpc_call_destroy(c);
198 grpc_call_destroy(s);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800199
Craig Tillera82950e2015-09-22 12:33:20 -0700200 cq_verifier_destroy(cqv);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800201}
202
Craig Tillera82950e2015-09-22 12:33:20 -0700203static void test_max_concurrent_streams(grpc_end2end_test_config config) {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800204 grpc_end2end_test_fixture f;
205 grpc_arg server_arg;
206 grpc_channel_args server_args;
207 grpc_call *c1;
208 grpc_call *c2;
209 grpc_call *s1;
210 grpc_call *s2;
ctiller58393c22015-01-07 14:03:30 -0800211 int live_call;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800212 gpr_timespec deadline;
Craig Tillerbc0ec332015-05-11 12:11:32 -0700213 cq_verifier *cqv;
Craig Tiller64be9f72015-05-04 14:53:51 -0700214 grpc_event ev;
Craig Tiller3b05a122015-04-28 15:14:40 -0700215 grpc_call_details call_details;
216 grpc_metadata_array request_metadata_recv;
217 grpc_metadata_array initial_metadata_recv1;
218 grpc_metadata_array trailing_metadata_recv1;
219 grpc_metadata_array initial_metadata_recv2;
220 grpc_metadata_array trailing_metadata_recv2;
221 grpc_status_code status1;
Nicolas "Pixel" Noble9a123df2015-07-29 23:45:08 +0200222 grpc_call_error error;
Craig Tiller3b05a122015-04-28 15:14:40 -0700223 char *details1 = NULL;
224 size_t details_capacity1 = 0;
225 grpc_status_code status2;
226 char *details2 = NULL;
227 size_t details_capacity2 = 0;
Craig Tillerfe2b8352015-04-28 15:46:50 -0700228 grpc_op ops[6];
229 grpc_op *op;
230 int was_cancelled;
Craig Tiller4a716002015-05-11 14:31:58 -0700231 int got_client_start;
232 int got_server_start;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800233
234 server_arg.key = GRPC_ARG_MAX_CONCURRENT_STREAMS;
235 server_arg.type = GRPC_ARG_INTEGER;
236 server_arg.value.integer = 1;
237
238 server_args.num_args = 1;
239 server_args.args = &server_arg;
240
Craig Tillera82950e2015-09-22 12:33:20 -0700241 f = begin_test(config, "test_max_concurrent_streams", NULL, &server_args);
242 cqv = cq_verifier_create(f.cq);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800243
Craig Tillera82950e2015-09-22 12:33:20 -0700244 grpc_metadata_array_init(&request_metadata_recv);
245 grpc_metadata_array_init(&initial_metadata_recv1);
246 grpc_metadata_array_init(&trailing_metadata_recv1);
247 grpc_metadata_array_init(&initial_metadata_recv2);
248 grpc_metadata_array_init(&trailing_metadata_recv2);
249 grpc_call_details_init(&call_details);
Craig Tiller3b05a122015-04-28 15:14:40 -0700250
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800251 /* perform a ping-pong to ensure that settings have had a chance to round
252 trip */
Craig Tillera82950e2015-09-22 12:33:20 -0700253 simple_request_body(f);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800254 /* perform another one to make sure that the one stream case still works */
Craig Tillera82950e2015-09-22 12:33:20 -0700255 simple_request_body(f);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800256
257 /* start two requests - ensuring that the second is not accepted until
258 the first completes */
Craig Tillera82950e2015-09-22 12:33:20 -0700259 deadline = n_seconds_time(1000);
260 c1 = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq,
261 "/alpha", "foo.test.google.fr:1234", deadline,
262 NULL);
263 GPR_ASSERT(c1);
264 c2 = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq,
265 "/beta", "foo.test.google.fr:1234", deadline,
266 NULL);
267 GPR_ASSERT(c2);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800268
Craig Tillera82950e2015-09-22 12:33:20 -0700269 GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(
270 f.server, &s1, &call_details,
271 &request_metadata_recv, f.cq, f.cq, tag(101)));
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800272
Craig Tiller3b05a122015-04-28 15:14:40 -0700273 op = ops;
274 op->op = GRPC_OP_SEND_INITIAL_METADATA;
275 op->data.send_initial_metadata.count = 0;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700276 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200277 op->reserved = NULL;
Craig Tiller3b05a122015-04-28 15:14:40 -0700278 op++;
279 op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700280 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200281 op->reserved = NULL;
Craig Tiller3b05a122015-04-28 15:14:40 -0700282 op++;
Craig Tillera82950e2015-09-22 12:33:20 -0700283 error = grpc_call_start_batch(c1, ops, (size_t)(op - ops), tag(301), NULL);
284 GPR_ASSERT(GRPC_CALL_OK == error);
Craig Tiller3b05a122015-04-28 15:14:40 -0700285
286 op = ops;
287 op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
Craig Tillerfe2b8352015-04-28 15:46:50 -0700288 op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv1;
289 op->data.recv_status_on_client.status = &status1;
290 op->data.recv_status_on_client.status_details = &details1;
291 op->data.recv_status_on_client.status_details_capacity = &details_capacity1;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700292 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200293 op->reserved = NULL;
Craig Tiller3b05a122015-04-28 15:14:40 -0700294 op++;
Craig Tiller06eb5ae2015-04-30 13:48:58 -0700295 op->op = GRPC_OP_RECV_INITIAL_METADATA;
296 op->data.recv_initial_metadata = &initial_metadata_recv1;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700297 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200298 op->reserved = NULL;
Craig Tiller06eb5ae2015-04-30 13:48:58 -0700299 op++;
Craig Tillera82950e2015-09-22 12:33:20 -0700300 error = grpc_call_start_batch(c1, ops, (size_t)(op - ops), tag(302), NULL);
301 GPR_ASSERT(GRPC_CALL_OK == error);
Craig Tiller3b05a122015-04-28 15:14:40 -0700302
303 op = ops;
304 op->op = GRPC_OP_SEND_INITIAL_METADATA;
305 op->data.send_initial_metadata.count = 0;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700306 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200307 op->reserved = NULL;
Craig Tiller3b05a122015-04-28 15:14:40 -0700308 op++;
309 op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700310 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200311 op->reserved = NULL;
Craig Tiller3b05a122015-04-28 15:14:40 -0700312 op++;
Craig Tillera82950e2015-09-22 12:33:20 -0700313 error = grpc_call_start_batch(c2, ops, (size_t)(op - ops), tag(401), NULL);
314 GPR_ASSERT(GRPC_CALL_OK == error);
Craig Tiller3b05a122015-04-28 15:14:40 -0700315
316 op = ops;
317 op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
Craig Tillerfe2b8352015-04-28 15:46:50 -0700318 op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv2;
319 op->data.recv_status_on_client.status = &status2;
320 op->data.recv_status_on_client.status_details = &details2;
321 op->data.recv_status_on_client.status_details_capacity = &details_capacity2;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700322 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200323 op->reserved = NULL;
Craig Tiller3b05a122015-04-28 15:14:40 -0700324 op++;
Craig Tiller06eb5ae2015-04-30 13:48:58 -0700325 op->op = GRPC_OP_RECV_INITIAL_METADATA;
326 op->data.recv_initial_metadata = &initial_metadata_recv1;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700327 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200328 op->reserved = NULL;
Craig Tiller06eb5ae2015-04-30 13:48:58 -0700329 op++;
Craig Tillera82950e2015-09-22 12:33:20 -0700330 error = grpc_call_start_batch(c2, ops, (size_t)(op - ops), tag(402), NULL);
331 GPR_ASSERT(GRPC_CALL_OK == error);
Craig Tiller80fa15c2015-01-13 16:10:49 -0800332
Craig Tiller4a716002015-05-11 14:31:58 -0700333 got_client_start = 0;
334 got_server_start = 0;
Craig Tillera0a6b122015-05-12 14:42:27 -0700335 live_call = -1;
Craig Tillera82950e2015-09-22 12:33:20 -0700336 while (!got_client_start || !got_server_start) {
337 ev = grpc_completion_queue_next(f.cq, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(3),
338 NULL);
339 GPR_ASSERT(ev.type == GRPC_OP_COMPLETE);
340 GPR_ASSERT(ev.success);
341 if (ev.tag == tag(101)) {
342 GPR_ASSERT(!got_server_start);
343 got_server_start = 1;
344 } else {
345 GPR_ASSERT(!got_client_start);
346 GPR_ASSERT(ev.tag == tag(301) || ev.tag == tag(401));
347 /* The /alpha or /beta calls started above could be invoked (but NOT
348 * both);
349 * check this here */
350 /* We'll get tag 303 or 403, we want 300, 400 */
351 live_call = ((int)(gpr_intptr)ev.tag) - 1;
352 got_client_start = 1;
Craig Tiller4a716002015-05-11 14:31:58 -0700353 }
Craig Tillera82950e2015-09-22 12:33:20 -0700354 }
355 GPR_ASSERT(live_call == 300 || live_call == 400);
ctiller58393c22015-01-07 14:03:30 -0800356
Craig Tiller3b05a122015-04-28 15:14:40 -0700357 op = ops;
358 op->op = GRPC_OP_SEND_INITIAL_METADATA;
359 op->data.send_initial_metadata.count = 0;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700360 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200361 op->reserved = NULL;
Craig Tiller3b05a122015-04-28 15:14:40 -0700362 op++;
363 op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
364 op->data.recv_close_on_server.cancelled = &was_cancelled;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700365 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200366 op->reserved = NULL;
Craig Tiller3b05a122015-04-28 15:14:40 -0700367 op++;
Craig Tiller3b05a122015-04-28 15:14:40 -0700368 op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
369 op->data.send_status_from_server.trailing_metadata_count = 0;
370 op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED;
371 op->data.send_status_from_server.status_details = "xyz";
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700372 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200373 op->reserved = NULL;
Craig Tiller3b05a122015-04-28 15:14:40 -0700374 op++;
Craig Tillera82950e2015-09-22 12:33:20 -0700375 error = grpc_call_start_batch(s1, ops, (size_t)(op - ops), tag(102), NULL);
376 GPR_ASSERT(GRPC_CALL_OK == error);
Craig Tiller3b05a122015-04-28 15:14:40 -0700377
Craig Tillera82950e2015-09-22 12:33:20 -0700378 cq_expect_completion(cqv, tag(102), 1);
379 cq_expect_completion(cqv, tag(live_call + 2), 1);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800380 /* first request is finished, we should be able to start the second */
Craig Tillerbf444932015-01-13 17:13:08 -0800381 live_call = (live_call == 300) ? 400 : 300;
Craig Tillera82950e2015-09-22 12:33:20 -0700382 cq_expect_completion(cqv, tag(live_call + 1), 1);
383 cq_verify(cqv);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800384
Craig Tillera82950e2015-09-22 12:33:20 -0700385 GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(
386 f.server, &s2, &call_details,
387 &request_metadata_recv, f.cq, f.cq, tag(201)));
388 cq_expect_completion(cqv, tag(201), 1);
389 cq_verify(cqv);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800390
Craig Tiller3b05a122015-04-28 15:14:40 -0700391 op = ops;
392 op->op = GRPC_OP_SEND_INITIAL_METADATA;
393 op->data.send_initial_metadata.count = 0;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700394 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200395 op->reserved = NULL;
Craig Tiller3b05a122015-04-28 15:14:40 -0700396 op++;
397 op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
398 op->data.recv_close_on_server.cancelled = &was_cancelled;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700399 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200400 op->reserved = NULL;
Craig Tiller3b05a122015-04-28 15:14:40 -0700401 op++;
Craig Tillerfe2b8352015-04-28 15:46:50 -0700402 op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
403 op->data.send_status_from_server.trailing_metadata_count = 0;
404 op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED;
405 op->data.send_status_from_server.status_details = "xyz";
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700406 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200407 op->reserved = NULL;
Craig Tillerfe2b8352015-04-28 15:46:50 -0700408 op++;
Craig Tillera82950e2015-09-22 12:33:20 -0700409 error = grpc_call_start_batch(s2, ops, (size_t)(op - ops), tag(202), NULL);
410 GPR_ASSERT(GRPC_CALL_OK == error);
Craig Tiller06eb5ae2015-04-30 13:48:58 -0700411
Craig Tillera82950e2015-09-22 12:33:20 -0700412 cq_expect_completion(cqv, tag(live_call + 2), 1);
413 cq_expect_completion(cqv, tag(202), 1);
414 cq_verify(cqv);
Craig Tillerfe2b8352015-04-28 15:46:50 -0700415
Craig Tillera82950e2015-09-22 12:33:20 -0700416 cq_verifier_destroy(cqv);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800417
Craig Tillera82950e2015-09-22 12:33:20 -0700418 grpc_call_destroy(c1);
419 grpc_call_destroy(s1);
420 grpc_call_destroy(c2);
421 grpc_call_destroy(s2);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800422
Craig Tillera82950e2015-09-22 12:33:20 -0700423 gpr_free(details1);
424 gpr_free(details2);
425 grpc_metadata_array_destroy(&initial_metadata_recv1);
426 grpc_metadata_array_destroy(&trailing_metadata_recv1);
427 grpc_metadata_array_destroy(&initial_metadata_recv2);
428 grpc_metadata_array_destroy(&trailing_metadata_recv2);
429 grpc_metadata_array_destroy(&request_metadata_recv);
430 grpc_call_details_destroy(&call_details);
Craig Tiller5fe7e5d2015-05-01 10:52:35 -0700431
Craig Tillera82950e2015-09-22 12:33:20 -0700432 end_test(&f);
433 config.tear_down_data(&f);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800434}
435
Craig Tillera82950e2015-09-22 12:33:20 -0700436void grpc_end2end_tests(grpc_end2end_test_config config) {
437 test_max_concurrent_streams(config);
Craig Tiller190d3602015-02-18 09:23:38 -0800438}