blob: 1204c070af45d4981d165ccf8328769c826b526a [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
46enum { TIMEOUT = 200000 };
47
48static void *tag(gpr_intptr t) { return (void *)t; }
49
50static 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
62static gpr_timespec n_seconds_time(int n) {
Craig Tiller8ad8a412015-02-25 08:36:40 -080063 return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(n);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080064}
65
Craig Tiller32946d32015-01-15 11:37:30 -080066static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080067
68static void drain_cq(grpc_completion_queue *cq) {
Craig Tiller64be9f72015-05-04 14:53:51 -070069 grpc_event ev;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080070 do {
71 ev = grpc_completion_queue_next(cq, five_seconds_time());
Craig Tiller64be9f72015-05-04 14:53:51 -070072 } while (ev.type != GRPC_QUEUE_SHUTDOWN);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080073}
74
75static void shutdown_server(grpc_end2end_test_fixture *f) {
76 if (!f->server) return;
Craig Tillerba2e7552015-05-28 12:53:54 -070077 grpc_server_shutdown_and_notify(f->server, f->cq, tag(1000));
Craig Tiller9a576332015-06-17 10:21:49 -070078 GPR_ASSERT(grpc_completion_queue_pluck(f->cq, tag(1000),
79 GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5))
80 .type == GRPC_OP_COMPLETE);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080081 grpc_server_destroy(f->server);
82 f->server = NULL;
83}
84
85static void shutdown_client(grpc_end2end_test_fixture *f) {
86 if (!f->client) return;
87 grpc_channel_destroy(f->client);
88 f->client = NULL;
89}
90
91static void end_test(grpc_end2end_test_fixture *f) {
92 shutdown_server(f);
93 shutdown_client(f);
94
Craig Tillerbc0ec332015-05-11 12:11:32 -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
100static void simple_request_body(grpc_end2end_test_fixture f) {
101 grpc_call *c;
102 grpc_call *s;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800103 gpr_timespec deadline = five_seconds_time();
Craig Tillerbc0ec332015-05-11 12:11:32 -0700104 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;
112 char *details = NULL;
113 size_t details_capacity = 0;
114 int was_cancelled = 2;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800115
Craig Tillerbc0ec332015-05-11 12:11:32 -0700116 c = grpc_channel_create_call(f.client, f.cq, "/foo",
Craig Tiller8b1d9892015-04-28 14:28:19 -0700117 "foo.test.google.fr:1234", deadline);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800118 GPR_ASSERT(c);
119
Craig Tiller8b1d9892015-04-28 14:28:19 -0700120 grpc_metadata_array_init(&initial_metadata_recv);
121 grpc_metadata_array_init(&trailing_metadata_recv);
122 grpc_metadata_array_init(&request_metadata_recv);
123 grpc_call_details_init(&call_details);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800124
Craig Tiller8b1d9892015-04-28 14:28:19 -0700125 op = ops;
126 op->op = GRPC_OP_SEND_INITIAL_METADATA;
127 op->data.send_initial_metadata.count = 0;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700128 op->flags = 0;
Craig Tiller8b1d9892015-04-28 14:28:19 -0700129 op++;
130 op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700131 op->flags = 0;
Craig Tiller8b1d9892015-04-28 14:28:19 -0700132 op++;
133 op->op = GRPC_OP_RECV_INITIAL_METADATA;
134 op->data.recv_initial_metadata = &initial_metadata_recv;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700135 op->flags = 0;
Craig Tiller8b1d9892015-04-28 14:28:19 -0700136 op++;
137 op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
138 op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
139 op->data.recv_status_on_client.status = &status;
140 op->data.recv_status_on_client.status_details = &details;
141 op->data.recv_status_on_client.status_details_capacity = &details_capacity;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700142 op->flags = 0;
Craig Tiller8b1d9892015-04-28 14:28:19 -0700143 op++;
144 GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(c, ops, op - ops, tag(1)));
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800145
Craig Tiller9a576332015-06-17 10:21:49 -0700146 GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(
147 f.server, &s, &call_details,
148 &request_metadata_recv, f.cq, f.cq, tag(101)));
Craig Tillera0a6b122015-05-12 14:42:27 -0700149 cq_expect_completion(cqv, tag(101), 1);
Craig Tillerbc0ec332015-05-11 12:11:32 -0700150 cq_verify(cqv);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800151
Craig Tiller8b1d9892015-04-28 14:28:19 -0700152 op = ops;
153 op->op = GRPC_OP_SEND_INITIAL_METADATA;
154 op->data.send_initial_metadata.count = 0;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700155 op->flags = 0;
Craig Tiller8b1d9892015-04-28 14:28:19 -0700156 op++;
157 op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
158 op->data.send_status_from_server.trailing_metadata_count = 0;
159 op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED;
160 op->data.send_status_from_server.status_details = "xyz";
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700161 op->flags = 0;
Craig Tiller8b1d9892015-04-28 14:28:19 -0700162 op++;
163 op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
164 op->data.recv_close_on_server.cancelled = &was_cancelled;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700165 op->flags = 0;
Craig Tiller8b1d9892015-04-28 14:28:19 -0700166 op++;
167 GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(s, ops, op - ops, tag(102)));
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800168
Craig Tillera0a6b122015-05-12 14:42:27 -0700169 cq_expect_completion(cqv, tag(102), 1);
170 cq_expect_completion(cqv, tag(1), 1);
Craig Tillerbc0ec332015-05-11 12:11:32 -0700171 cq_verify(cqv);
Craig Tiller8b1d9892015-04-28 14:28:19 -0700172
173 GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
174 GPR_ASSERT(0 == strcmp(details, "xyz"));
175 GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
176 GPR_ASSERT(0 == strcmp(call_details.host, "foo.test.google.fr:1234"));
Craig Tilleraea081f2015-06-11 14:19:33 -0700177 GPR_ASSERT(was_cancelled == 1);
Craig Tiller8b1d9892015-04-28 14:28:19 -0700178
179 gpr_free(details);
180 grpc_metadata_array_destroy(&initial_metadata_recv);
181 grpc_metadata_array_destroy(&trailing_metadata_recv);
182 grpc_metadata_array_destroy(&request_metadata_recv);
183 grpc_call_details_destroy(&call_details);
184
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800185 grpc_call_destroy(c);
186 grpc_call_destroy(s);
187
Craig Tillerbc0ec332015-05-11 12:11:32 -0700188 cq_verifier_destroy(cqv);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800189}
190
191static void test_max_concurrent_streams(grpc_end2end_test_config config) {
192 grpc_end2end_test_fixture f;
193 grpc_arg server_arg;
194 grpc_channel_args server_args;
195 grpc_call *c1;
196 grpc_call *c2;
197 grpc_call *s1;
198 grpc_call *s2;
ctiller58393c22015-01-07 14:03:30 -0800199 int live_call;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800200 gpr_timespec deadline;
Craig Tillerbc0ec332015-05-11 12:11:32 -0700201 cq_verifier *cqv;
Craig Tiller64be9f72015-05-04 14:53:51 -0700202 grpc_event ev;
Craig Tiller3b05a122015-04-28 15:14:40 -0700203 grpc_call_details call_details;
204 grpc_metadata_array request_metadata_recv;
205 grpc_metadata_array initial_metadata_recv1;
206 grpc_metadata_array trailing_metadata_recv1;
207 grpc_metadata_array initial_metadata_recv2;
208 grpc_metadata_array trailing_metadata_recv2;
209 grpc_status_code status1;
210 char *details1 = NULL;
211 size_t details_capacity1 = 0;
212 grpc_status_code status2;
213 char *details2 = NULL;
214 size_t details_capacity2 = 0;
Craig Tillerfe2b8352015-04-28 15:46:50 -0700215 grpc_op ops[6];
216 grpc_op *op;
217 int was_cancelled;
Craig Tiller4a716002015-05-11 14:31:58 -0700218 int got_client_start;
219 int got_server_start;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800220
221 server_arg.key = GRPC_ARG_MAX_CONCURRENT_STREAMS;
222 server_arg.type = GRPC_ARG_INTEGER;
223 server_arg.value.integer = 1;
224
225 server_args.num_args = 1;
226 server_args.args = &server_arg;
227
Craig Tiller35696192015-05-24 15:00:37 -0700228 f = begin_test(config, "test_max_concurrent_streams", NULL, &server_args);
Craig Tillerbc0ec332015-05-11 12:11:32 -0700229 cqv = cq_verifier_create(f.cq);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800230
Craig Tiller3b05a122015-04-28 15:14:40 -0700231 grpc_metadata_array_init(&request_metadata_recv);
Craig Tillerf1071202015-04-30 13:29:48 -0700232 grpc_metadata_array_init(&initial_metadata_recv1);
233 grpc_metadata_array_init(&trailing_metadata_recv1);
234 grpc_metadata_array_init(&initial_metadata_recv2);
235 grpc_metadata_array_init(&trailing_metadata_recv2);
236 grpc_call_details_init(&call_details);
Craig Tiller3b05a122015-04-28 15:14:40 -0700237
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800238 /* perform a ping-pong to ensure that settings have had a chance to round
239 trip */
240 simple_request_body(f);
241 /* perform another one to make sure that the one stream case still works */
242 simple_request_body(f);
243
244 /* start two requests - ensuring that the second is not accepted until
245 the first completes */
Craig Tiller4a716002015-05-11 14:31:58 -0700246 deadline = n_seconds_time(1000);
Craig Tillerbc0ec332015-05-11 12:11:32 -0700247 c1 = grpc_channel_create_call(f.client, f.cq, "/alpha",
Craig Tiller9f3675f2015-04-29 13:56:33 -0700248 "foo.test.google.fr:1234", deadline);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800249 GPR_ASSERT(c1);
Craig Tillerbc0ec332015-05-11 12:11:32 -0700250 c2 = grpc_channel_create_call(f.client, f.cq, "/beta",
Craig Tiller9f3675f2015-04-29 13:56:33 -0700251 "foo.test.google.fr:1234", deadline);
Craig Tiller3b05a122015-04-28 15:14:40 -0700252 GPR_ASSERT(c2);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800253
Craig Tiller9a576332015-06-17 10:21:49 -0700254 GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(
255 f.server, &s1, &call_details,
256 &request_metadata_recv, f.cq, f.cq, tag(101)));
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800257
Craig Tiller3b05a122015-04-28 15:14:40 -0700258 op = ops;
259 op->op = GRPC_OP_SEND_INITIAL_METADATA;
260 op->data.send_initial_metadata.count = 0;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700261 op->flags = 0;
Craig Tiller3b05a122015-04-28 15:14:40 -0700262 op++;
263 op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700264 op->flags = 0;
Craig Tiller3b05a122015-04-28 15:14:40 -0700265 op++;
Craig Tiller9f3675f2015-04-29 13:56:33 -0700266 GPR_ASSERT(GRPC_CALL_OK ==
267 grpc_call_start_batch(c1, ops, op - ops, tag(301)));
Craig Tiller3b05a122015-04-28 15:14:40 -0700268
269 op = ops;
270 op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
Craig Tillerfe2b8352015-04-28 15:46:50 -0700271 op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv1;
272 op->data.recv_status_on_client.status = &status1;
273 op->data.recv_status_on_client.status_details = &details1;
274 op->data.recv_status_on_client.status_details_capacity = &details_capacity1;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700275 op->flags = 0;
Craig Tiller3b05a122015-04-28 15:14:40 -0700276 op++;
Craig Tiller06eb5ae2015-04-30 13:48:58 -0700277 op->op = GRPC_OP_RECV_INITIAL_METADATA;
278 op->data.recv_initial_metadata = &initial_metadata_recv1;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700279 op->flags = 0;
Craig Tiller06eb5ae2015-04-30 13:48:58 -0700280 op++;
Craig Tiller9f3675f2015-04-29 13:56:33 -0700281 GPR_ASSERT(GRPC_CALL_OK ==
282 grpc_call_start_batch(c1, ops, op - ops, tag(302)));
Craig Tiller3b05a122015-04-28 15:14:40 -0700283
284 op = ops;
285 op->op = GRPC_OP_SEND_INITIAL_METADATA;
286 op->data.send_initial_metadata.count = 0;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700287 op->flags = 0;
Craig Tiller3b05a122015-04-28 15:14:40 -0700288 op++;
289 op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700290 op->flags = 0;
Craig Tiller3b05a122015-04-28 15:14:40 -0700291 op++;
Craig Tiller9f3675f2015-04-29 13:56:33 -0700292 GPR_ASSERT(GRPC_CALL_OK ==
293 grpc_call_start_batch(c2, ops, op - ops, tag(401)));
Craig Tiller3b05a122015-04-28 15:14:40 -0700294
295 op = ops;
296 op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
Craig Tillerfe2b8352015-04-28 15:46:50 -0700297 op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv2;
298 op->data.recv_status_on_client.status = &status2;
299 op->data.recv_status_on_client.status_details = &details2;
300 op->data.recv_status_on_client.status_details_capacity = &details_capacity2;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700301 op->flags = 0;
Craig Tiller3b05a122015-04-28 15:14:40 -0700302 op++;
Craig Tiller06eb5ae2015-04-30 13:48:58 -0700303 op->op = GRPC_OP_RECV_INITIAL_METADATA;
304 op->data.recv_initial_metadata = &initial_metadata_recv1;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700305 op->flags = 0;
Craig Tiller06eb5ae2015-04-30 13:48:58 -0700306 op++;
Craig Tiller9f3675f2015-04-29 13:56:33 -0700307 GPR_ASSERT(GRPC_CALL_OK ==
308 grpc_call_start_batch(c2, ops, op - ops, tag(402)));
Craig Tiller80fa15c2015-01-13 16:10:49 -0800309
Craig Tiller4a716002015-05-11 14:31:58 -0700310 got_client_start = 0;
311 got_server_start = 0;
Craig Tillera0a6b122015-05-12 14:42:27 -0700312 live_call = -1;
Craig Tiller4a716002015-05-11 14:31:58 -0700313 while (!got_client_start || !got_server_start) {
Craig Tiller9a576332015-06-17 10:21:49 -0700314 ev = grpc_completion_queue_next(f.cq, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(3));
Craig Tillera0a6b122015-05-12 14:42:27 -0700315 GPR_ASSERT(ev.type == GRPC_OP_COMPLETE);
316 GPR_ASSERT(ev.success);
317 if (ev.tag == tag(101)) {
Craig Tiller4a716002015-05-11 14:31:58 -0700318 GPR_ASSERT(!got_server_start);
319 got_server_start = 1;
320 } else {
321 GPR_ASSERT(!got_client_start);
Craig Tillera0a6b122015-05-12 14:42:27 -0700322 GPR_ASSERT(ev.tag == tag(301) || ev.tag == tag(401));
Craig Tiller9a576332015-06-17 10:21:49 -0700323 /* The /alpha or /beta calls started above could be invoked (but NOT
324 * both);
Craig Tiller4a716002015-05-11 14:31:58 -0700325 * check this here */
326 /* We'll get tag 303 or 403, we want 300, 400 */
Craig Tillera0a6b122015-05-12 14:42:27 -0700327 live_call = ((int)(gpr_intptr)ev.tag) - 1;
Craig Tiller4a716002015-05-11 14:31:58 -0700328 got_client_start = 1;
329 }
Craig Tiller4a716002015-05-11 14:31:58 -0700330 }
Craig Tillera0a6b122015-05-12 14:42:27 -0700331 GPR_ASSERT(live_call == 300 || live_call == 400);
ctiller58393c22015-01-07 14:03:30 -0800332
Craig Tiller3b05a122015-04-28 15:14:40 -0700333 op = ops;
334 op->op = GRPC_OP_SEND_INITIAL_METADATA;
335 op->data.send_initial_metadata.count = 0;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700336 op->flags = 0;
Craig Tiller3b05a122015-04-28 15:14:40 -0700337 op++;
338 op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
339 op->data.recv_close_on_server.cancelled = &was_cancelled;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700340 op->flags = 0;
Craig Tiller3b05a122015-04-28 15:14:40 -0700341 op++;
Craig Tiller3b05a122015-04-28 15:14:40 -0700342 op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
343 op->data.send_status_from_server.trailing_metadata_count = 0;
344 op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED;
345 op->data.send_status_from_server.status_details = "xyz";
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700346 op->flags = 0;
Craig Tiller3b05a122015-04-28 15:14:40 -0700347 op++;
Craig Tiller9f3675f2015-04-29 13:56:33 -0700348 GPR_ASSERT(GRPC_CALL_OK ==
Craig Tiller06eb5ae2015-04-30 13:48:58 -0700349 grpc_call_start_batch(s1, ops, op - ops, tag(102)));
Craig Tiller3b05a122015-04-28 15:14:40 -0700350
Craig Tillera0a6b122015-05-12 14:42:27 -0700351 cq_expect_completion(cqv, tag(102), 1);
352 cq_expect_completion(cqv, tag(live_call + 2), 1);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800353 /* first request is finished, we should be able to start the second */
Craig Tillerbf444932015-01-13 17:13:08 -0800354 live_call = (live_call == 300) ? 400 : 300;
Craig Tillera0a6b122015-05-12 14:42:27 -0700355 cq_expect_completion(cqv, tag(live_call + 1), 1);
Craig Tillerbc0ec332015-05-11 12:11:32 -0700356 cq_verify(cqv);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800357
Craig Tiller9a576332015-06-17 10:21:49 -0700358 GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(
359 f.server, &s2, &call_details,
360 &request_metadata_recv, f.cq, f.cq, tag(201)));
Craig Tillera0a6b122015-05-12 14:42:27 -0700361 cq_expect_completion(cqv, tag(201), 1);
Craig Tillerbc0ec332015-05-11 12:11:32 -0700362 cq_verify(cqv);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800363
Craig Tiller3b05a122015-04-28 15:14:40 -0700364 op = ops;
365 op->op = GRPC_OP_SEND_INITIAL_METADATA;
366 op->data.send_initial_metadata.count = 0;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700367 op->flags = 0;
Craig Tiller3b05a122015-04-28 15:14:40 -0700368 op++;
369 op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
370 op->data.recv_close_on_server.cancelled = &was_cancelled;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700371 op->flags = 0;
Craig Tiller3b05a122015-04-28 15:14:40 -0700372 op++;
Craig Tillerfe2b8352015-04-28 15:46:50 -0700373 op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
374 op->data.send_status_from_server.trailing_metadata_count = 0;
375 op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED;
376 op->data.send_status_from_server.status_details = "xyz";
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700377 op->flags = 0;
Craig Tillerfe2b8352015-04-28 15:46:50 -0700378 op++;
Craig Tiller9f3675f2015-04-29 13:56:33 -0700379 GPR_ASSERT(GRPC_CALL_OK ==
Craig Tiller06eb5ae2015-04-30 13:48:58 -0700380 grpc_call_start_batch(s2, ops, op - ops, tag(202)));
381
Craig Tillera0a6b122015-05-12 14:42:27 -0700382 cq_expect_completion(cqv, tag(live_call + 2), 1);
383 cq_expect_completion(cqv, tag(202), 1);
Craig Tillerbc0ec332015-05-11 12:11:32 -0700384 cq_verify(cqv);
Craig Tillerfe2b8352015-04-28 15:46:50 -0700385
Craig Tillerbc0ec332015-05-11 12:11:32 -0700386 cq_verifier_destroy(cqv);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800387
388 grpc_call_destroy(c1);
389 grpc_call_destroy(s1);
390 grpc_call_destroy(c2);
391 grpc_call_destroy(s2);
392
Craig Tiller5fe7e5d2015-05-01 10:52:35 -0700393 gpr_free(details1);
394 gpr_free(details2);
395 grpc_metadata_array_destroy(&initial_metadata_recv1);
396 grpc_metadata_array_destroy(&trailing_metadata_recv1);
397 grpc_metadata_array_destroy(&initial_metadata_recv2);
398 grpc_metadata_array_destroy(&trailing_metadata_recv2);
399 grpc_metadata_array_destroy(&request_metadata_recv);
400 grpc_call_details_destroy(&call_details);
401
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800402 end_test(&f);
403 config.tear_down_data(&f);
404}
405
406void grpc_end2end_tests(grpc_end2end_test_config config) {
407 test_max_concurrent_streams(config);
Craig Tiller190d3602015-02-18 09:23:38 -0800408}