blob: 1d4ba32ee08ce59063e1ff775a7096eef44b6b67 [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 Tiller45724b32015-09-22 10:42:19 -070046enum
47{ TIMEOUT = 200000 };
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080048
Craig Tiller45724b32015-09-22 10:42:19 -070049static void *
50tag (gpr_intptr t)
51{
52 return (void *) t;
53}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080054
Craig Tiller45724b32015-09-22 10:42:19 -070055static grpc_end2end_test_fixture
56begin_test (grpc_end2end_test_config config, const char *test_name, grpc_channel_args * client_args, grpc_channel_args * server_args)
57{
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080058 grpc_end2end_test_fixture f;
Craig Tiller45724b32015-09-22 10:42:19 -070059 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 Nobleb7ebd3b2014-11-26 16:33:03 -080063 return f;
64}
65
Craig Tiller45724b32015-09-22 10:42:19 -070066static gpr_timespec
67n_seconds_time (int n)
68{
69 return GRPC_TIMEOUT_SECONDS_TO_DEADLINE (n);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080070}
71
Craig Tiller45724b32015-09-22 10:42:19 -070072static gpr_timespec
73five_seconds_time (void)
74{
75 return n_seconds_time (5);
76}
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080077
Craig Tiller45724b32015-09-22 10:42:19 -070078static void
79drain_cq (grpc_completion_queue * cq)
80{
Craig Tiller64be9f72015-05-04 14:53:51 -070081 grpc_event ev;
Craig Tiller45724b32015-09-22 10:42:19 -070082 do
83 {
84 ev = grpc_completion_queue_next (cq, five_seconds_time (), NULL);
85 }
86 while (ev.type != GRPC_QUEUE_SHUTDOWN);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080087}
88
Craig Tiller45724b32015-09-22 10:42:19 -070089static void
90shutdown_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 Nobleb7ebd3b2014-11-26 16:33:03 -080097 f->server = NULL;
98}
99
Craig Tiller45724b32015-09-22 10:42:19 -0700100static void
101shutdown_client (grpc_end2end_test_fixture * f)
102{
103 if (!f->client)
104 return;
105 grpc_channel_destroy (f->client);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800106 f->client = NULL;
107}
108
Craig Tiller45724b32015-09-22 10:42:19 -0700109static void
110end_test (grpc_end2end_test_fixture * f)
111{
112 shutdown_server (f);
113 shutdown_client (f);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800114
Craig Tiller45724b32015-09-22 10:42:19 -0700115 grpc_completion_queue_shutdown (f->cq);
116 drain_cq (f->cq);
117 grpc_completion_queue_destroy (f->cq);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800118}
119
Craig Tiller45724b32015-09-22 10:42:19 -0700120static void
121simple_request_body (grpc_end2end_test_fixture f)
122{
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800123 grpc_call *c;
124 grpc_call *s;
Craig Tiller45724b32015-09-22 10:42:19 -0700125 gpr_timespec deadline = five_seconds_time ();
126 cq_verifier *cqv = cq_verifier_create (f.cq);
Craig Tiller8b1d9892015-04-28 14:28:19 -0700127 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" Noble9a123df2015-07-29 23:45:08 +0200134 grpc_call_error error;
Craig Tiller8b1d9892015-04-28 14:28:19 -0700135 char *details = NULL;
136 size_t details_capacity = 0;
137 int was_cancelled = 2;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800138
Craig Tiller45724b32015-09-22 10:42:19 -0700139 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 Nobleb7ebd3b2014-11-26 16:33:03 -0800141
Craig Tiller45724b32015-09-22 10:42:19 -0700142 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 Nobleb7ebd3b2014-11-26 16:33:03 -0800146
Craig Tiller8b1d9892015-04-28 14:28:19 -0700147 op = ops;
148 op->op = GRPC_OP_SEND_INITIAL_METADATA;
149 op->data.send_initial_metadata.count = 0;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700150 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200151 op->reserved = NULL;
Craig Tiller8b1d9892015-04-28 14:28:19 -0700152 op++;
153 op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700154 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200155 op->reserved = NULL;
Craig Tiller8b1d9892015-04-28 14:28:19 -0700156 op++;
157 op->op = GRPC_OP_RECV_INITIAL_METADATA;
158 op->data.recv_initial_metadata = &initial_metadata_recv;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700159 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200160 op->reserved = NULL;
Craig Tiller8b1d9892015-04-28 14:28:19 -0700161 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 Quintas1d5aca52015-06-14 14:42:04 -0700167 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200168 op->reserved = NULL;
Craig Tiller8b1d9892015-04-28 14:28:19 -0700169 op++;
Craig Tiller45724b32015-09-22 10:42:19 -0700170 error = grpc_call_start_batch (c, ops, (size_t) (op - ops), tag (1), NULL);
171 GPR_ASSERT (GRPC_CALL_OK == error);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800172
Craig Tiller45724b32015-09-22 10:42:19 -0700173 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 Nobleb7ebd3b2014-11-26 16:33:03 -0800177
Craig Tiller8b1d9892015-04-28 14:28:19 -0700178 op = ops;
179 op->op = GRPC_OP_SEND_INITIAL_METADATA;
180 op->data.send_initial_metadata.count = 0;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700181 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200182 op->reserved = NULL;
Craig Tiller8b1d9892015-04-28 14:28:19 -0700183 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 Quintas1d5aca52015-06-14 14:42:04 -0700188 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200189 op->reserved = NULL;
Craig Tiller8b1d9892015-04-28 14:28:19 -0700190 op++;
191 op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
192 op->data.recv_close_on_server.cancelled = &was_cancelled;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700193 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200194 op->reserved = NULL;
Craig Tiller8b1d9892015-04-28 14:28:19 -0700195 op++;
Craig Tiller45724b32015-09-22 10:42:19 -0700196 error = grpc_call_start_batch (s, ops, (size_t) (op - ops), tag (102), NULL);
197 GPR_ASSERT (GRPC_CALL_OK == error);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800198
Craig Tiller45724b32015-09-22 10:42:19 -0700199 cq_expect_completion (cqv, tag (102), 1);
200 cq_expect_completion (cqv, tag (1), 1);
201 cq_verify (cqv);
Craig Tiller8b1d9892015-04-28 14:28:19 -0700202
Craig Tiller45724b32015-09-22 10:42:19 -0700203 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 Tiller8b1d9892015-04-28 14:28:19 -0700208
Craig Tiller45724b32015-09-22 10:42:19 -0700209 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 Tiller8b1d9892015-04-28 14:28:19 -0700214
Craig Tiller45724b32015-09-22 10:42:19 -0700215 grpc_call_destroy (c);
216 grpc_call_destroy (s);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800217
Craig Tiller45724b32015-09-22 10:42:19 -0700218 cq_verifier_destroy (cqv);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800219}
220
Craig Tiller45724b32015-09-22 10:42:19 -0700221static void
222test_max_concurrent_streams (grpc_end2end_test_config config)
223{
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800224 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;
ctiller58393c22015-01-07 14:03:30 -0800231 int live_call;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800232 gpr_timespec deadline;
Craig Tillerbc0ec332015-05-11 12:11:32 -0700233 cq_verifier *cqv;
Craig Tiller64be9f72015-05-04 14:53:51 -0700234 grpc_event ev;
Craig Tiller3b05a122015-04-28 15:14:40 -0700235 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" Noble9a123df2015-07-29 23:45:08 +0200242 grpc_call_error error;
Craig Tiller3b05a122015-04-28 15:14:40 -0700243 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 Tillerfe2b8352015-04-28 15:46:50 -0700248 grpc_op ops[6];
249 grpc_op *op;
250 int was_cancelled;
Craig Tiller4a716002015-05-11 14:31:58 -0700251 int got_client_start;
252 int got_server_start;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800253
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 Tiller45724b32015-09-22 10:42:19 -0700261 f = begin_test (config, "test_max_concurrent_streams", NULL, &server_args);
262 cqv = cq_verifier_create (f.cq);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800263
Craig Tiller45724b32015-09-22 10:42:19 -0700264 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 Tiller3b05a122015-04-28 15:14:40 -0700270
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800271 /* perform a ping-pong to ensure that settings have had a chance to round
272 trip */
Craig Tiller45724b32015-09-22 10:42:19 -0700273 simple_request_body (f);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800274 /* perform another one to make sure that the one stream case still works */
Craig Tiller45724b32015-09-22 10:42:19 -0700275 simple_request_body (f);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800276
277 /* start two requests - ensuring that the second is not accepted until
278 the first completes */
Craig Tiller45724b32015-09-22 10:42:19 -0700279 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 Nobleb7ebd3b2014-11-26 16:33:03 -0800284
Craig Tiller45724b32015-09-22 10:42:19 -0700285 GPR_ASSERT (GRPC_CALL_OK == grpc_server_request_call (f.server, &s1, &call_details, &request_metadata_recv, f.cq, f.cq, tag (101)));
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800286
Craig Tiller3b05a122015-04-28 15:14:40 -0700287 op = ops;
288 op->op = GRPC_OP_SEND_INITIAL_METADATA;
289 op->data.send_initial_metadata.count = 0;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700290 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200291 op->reserved = NULL;
Craig Tiller3b05a122015-04-28 15:14:40 -0700292 op++;
293 op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700294 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200295 op->reserved = NULL;
Craig Tiller3b05a122015-04-28 15:14:40 -0700296 op++;
Craig Tiller45724b32015-09-22 10:42:19 -0700297 error = grpc_call_start_batch (c1, ops, (size_t) (op - ops), tag (301), NULL);
298 GPR_ASSERT (GRPC_CALL_OK == error);
Craig Tiller3b05a122015-04-28 15:14:40 -0700299
300 op = ops;
301 op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
Craig Tillerfe2b8352015-04-28 15:46:50 -0700302 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 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++;
Craig Tiller06eb5ae2015-04-30 13:48:58 -0700309 op->op = GRPC_OP_RECV_INITIAL_METADATA;
310 op->data.recv_initial_metadata = &initial_metadata_recv1;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700311 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200312 op->reserved = NULL;
Craig Tiller06eb5ae2015-04-30 13:48:58 -0700313 op++;
Craig Tiller45724b32015-09-22 10:42:19 -0700314 error = grpc_call_start_batch (c1, ops, (size_t) (op - ops), tag (302), NULL);
315 GPR_ASSERT (GRPC_CALL_OK == error);
Craig Tiller3b05a122015-04-28 15:14:40 -0700316
317 op = ops;
318 op->op = GRPC_OP_SEND_INITIAL_METADATA;
319 op->data.send_initial_metadata.count = 0;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700320 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200321 op->reserved = NULL;
Craig Tiller3b05a122015-04-28 15:14:40 -0700322 op++;
323 op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700324 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200325 op->reserved = NULL;
Craig Tiller3b05a122015-04-28 15:14:40 -0700326 op++;
Craig Tiller45724b32015-09-22 10:42:19 -0700327 error = grpc_call_start_batch (c2, ops, (size_t) (op - ops), tag (401), NULL);
328 GPR_ASSERT (GRPC_CALL_OK == error);
Craig Tiller3b05a122015-04-28 15:14:40 -0700329
330 op = ops;
331 op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
Craig Tillerfe2b8352015-04-28 15:46:50 -0700332 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 Quintas1d5aca52015-06-14 14:42:04 -0700336 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200337 op->reserved = NULL;
Craig Tiller3b05a122015-04-28 15:14:40 -0700338 op++;
Craig Tiller06eb5ae2015-04-30 13:48:58 -0700339 op->op = GRPC_OP_RECV_INITIAL_METADATA;
340 op->data.recv_initial_metadata = &initial_metadata_recv1;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700341 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200342 op->reserved = NULL;
Craig Tiller06eb5ae2015-04-30 13:48:58 -0700343 op++;
Craig Tiller45724b32015-09-22 10:42:19 -0700344 error = grpc_call_start_batch (c2, ops, (size_t) (op - ops), tag (402), NULL);
345 GPR_ASSERT (GRPC_CALL_OK == error);
Craig Tiller80fa15c2015-01-13 16:10:49 -0800346
Craig Tiller4a716002015-05-11 14:31:58 -0700347 got_client_start = 0;
348 got_server_start = 0;
Craig Tillera0a6b122015-05-12 14:42:27 -0700349 live_call = -1;
Craig Tiller45724b32015-09-22 10:42:19 -0700350 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 Tiller4a716002015-05-11 14:31:58 -0700371 }
Craig Tiller45724b32015-09-22 10:42:19 -0700372 GPR_ASSERT (live_call == 300 || live_call == 400);
ctiller58393c22015-01-07 14:03:30 -0800373
Craig Tiller3b05a122015-04-28 15:14:40 -0700374 op = ops;
375 op->op = GRPC_OP_SEND_INITIAL_METADATA;
376 op->data.send_initial_metadata.count = 0;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700377 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200378 op->reserved = NULL;
Craig Tiller3b05a122015-04-28 15:14:40 -0700379 op++;
380 op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
381 op->data.recv_close_on_server.cancelled = &was_cancelled;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700382 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200383 op->reserved = NULL;
Craig Tiller3b05a122015-04-28 15:14:40 -0700384 op++;
Craig Tiller3b05a122015-04-28 15:14:40 -0700385 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 Quintas1d5aca52015-06-14 14:42:04 -0700389 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200390 op->reserved = NULL;
Craig Tiller3b05a122015-04-28 15:14:40 -0700391 op++;
Craig Tiller45724b32015-09-22 10:42:19 -0700392 error = grpc_call_start_batch (s1, ops, (size_t) (op - ops), tag (102), NULL);
393 GPR_ASSERT (GRPC_CALL_OK == error);
Craig Tiller3b05a122015-04-28 15:14:40 -0700394
Craig Tiller45724b32015-09-22 10:42:19 -0700395 cq_expect_completion (cqv, tag (102), 1);
396 cq_expect_completion (cqv, tag (live_call + 2), 1);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800397 /* first request is finished, we should be able to start the second */
Craig Tillerbf444932015-01-13 17:13:08 -0800398 live_call = (live_call == 300) ? 400 : 300;
Craig Tiller45724b32015-09-22 10:42:19 -0700399 cq_expect_completion (cqv, tag (live_call + 1), 1);
400 cq_verify (cqv);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800401
Craig Tiller45724b32015-09-22 10:42:19 -0700402 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 Nobleb7ebd3b2014-11-26 16:33:03 -0800405
Craig Tiller3b05a122015-04-28 15:14:40 -0700406 op = ops;
407 op->op = GRPC_OP_SEND_INITIAL_METADATA;
408 op->data.send_initial_metadata.count = 0;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700409 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200410 op->reserved = NULL;
Craig Tiller3b05a122015-04-28 15:14:40 -0700411 op++;
412 op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
413 op->data.recv_close_on_server.cancelled = &was_cancelled;
David Garcia Quintas1d5aca52015-06-14 14:42:04 -0700414 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200415 op->reserved = NULL;
Craig Tiller3b05a122015-04-28 15:14:40 -0700416 op++;
Craig Tillerfe2b8352015-04-28 15:46:50 -0700417 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 Quintas1d5aca52015-06-14 14:42:04 -0700421 op->flags = 0;
Nicolas "Pixel" Noble49605162015-08-01 00:12:01 +0200422 op->reserved = NULL;
Craig Tillerfe2b8352015-04-28 15:46:50 -0700423 op++;
Craig Tiller45724b32015-09-22 10:42:19 -0700424 error = grpc_call_start_batch (s2, ops, (size_t) (op - ops), tag (202), NULL);
425 GPR_ASSERT (GRPC_CALL_OK == error);
Craig Tiller06eb5ae2015-04-30 13:48:58 -0700426
Craig Tiller45724b32015-09-22 10:42:19 -0700427 cq_expect_completion (cqv, tag (live_call + 2), 1);
428 cq_expect_completion (cqv, tag (202), 1);
429 cq_verify (cqv);
Craig Tillerfe2b8352015-04-28 15:46:50 -0700430
Craig Tiller45724b32015-09-22 10:42:19 -0700431 cq_verifier_destroy (cqv);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800432
Craig Tiller45724b32015-09-22 10:42:19 -0700433 grpc_call_destroy (c1);
434 grpc_call_destroy (s1);
435 grpc_call_destroy (c2);
436 grpc_call_destroy (s2);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800437
Craig Tiller45724b32015-09-22 10:42:19 -0700438 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 Tiller5fe7e5d2015-05-01 10:52:35 -0700446
Craig Tiller45724b32015-09-22 10:42:19 -0700447 end_test (&f);
448 config.tear_down_data (&f);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -0800449}
450
Craig Tiller45724b32015-09-22 10:42:19 -0700451void
452grpc_end2end_tests (grpc_end2end_test_config config)
453{
454 test_max_concurrent_streams (config);
Craig Tiller190d3602015-02-18 09:23:38 -0800455}