3
* Copyright 2015, Google Inc.
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions are
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
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.
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.
34
#include "test/core/end2end/end2end_tests.h"
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"
46
enum { TIMEOUT = 200000 };
48
static void *tag(gpr_intptr t) { return (void *)t; }
50
static gpr_timespec n_seconds_time(int n) {
51
return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(n);
54
static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
56
static void drain_cq(grpc_completion_queue *cq) {
59
ev = grpc_completion_queue_next(cq, five_seconds_time());
60
} while (ev.type != GRPC_QUEUE_SHUTDOWN);
63
static void shutdown_server(grpc_end2end_test_fixture *f) {
64
if (!f->server) return;
65
grpc_server_shutdown_and_notify(f->server, f->cq, tag(1000));
66
GPR_ASSERT(grpc_completion_queue_pluck(f->cq, tag(1000),
67
GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5))
68
.type == GRPC_OP_COMPLETE);
69
grpc_server_destroy(f->server);
73
static void shutdown_client(grpc_end2end_test_fixture *f) {
74
if (!f->client) return;
75
grpc_channel_destroy(f->client);
79
static void end_test(grpc_end2end_test_fixture *f) {
83
grpc_completion_queue_shutdown(f->cq);
85
grpc_completion_queue_destroy(f->cq);
88
static void simple_delayed_request_body(grpc_end2end_test_config config,
89
grpc_end2end_test_fixture *f,
90
grpc_channel_args *client_args,
91
grpc_channel_args *server_args,
95
gpr_timespec deadline = five_seconds_time();
96
cq_verifier *cqv = cq_verifier_create(f->cq);
99
grpc_metadata_array initial_metadata_recv;
100
grpc_metadata_array trailing_metadata_recv;
101
grpc_metadata_array request_metadata_recv;
102
grpc_call_details call_details;
103
grpc_status_code status;
104
char *details = NULL;
105
size_t details_capacity = 0;
106
int was_cancelled = 2;
108
config.init_client(f, client_args);
110
c = grpc_channel_create_call(f->client, f->cq, "/foo", "foo.test.google.fr",
114
grpc_metadata_array_init(&initial_metadata_recv);
115
grpc_metadata_array_init(&trailing_metadata_recv);
116
grpc_metadata_array_init(&request_metadata_recv);
117
grpc_call_details_init(&call_details);
120
op->op = GRPC_OP_SEND_INITIAL_METADATA;
121
op->data.send_initial_metadata.count = 0;
124
op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
127
op->op = GRPC_OP_RECV_INITIAL_METADATA;
128
op->data.recv_initial_metadata = &initial_metadata_recv;
131
op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
132
op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
133
op->data.recv_status_on_client.status = &status;
134
op->data.recv_status_on_client.status_details = &details;
135
op->data.recv_status_on_client.status_details_capacity = &details_capacity;
138
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(c, ops, op - ops, tag(1)));
140
config.init_server(f, server_args);
142
GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(f->server, &s,
144
&request_metadata_recv,
145
f->cq, f->cq, tag(101)));
146
cq_expect_completion(cqv, tag(101), 1);
150
op->op = GRPC_OP_SEND_INITIAL_METADATA;
151
op->data.send_initial_metadata.count = 0;
154
op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
155
op->data.send_status_from_server.trailing_metadata_count = 0;
156
op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED;
157
op->data.send_status_from_server.status_details = "xyz";
160
op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
161
op->data.recv_close_on_server.cancelled = &was_cancelled;
164
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(s, ops, op - ops, tag(102)));
166
cq_expect_completion(cqv, tag(102), 1);
167
cq_expect_completion(cqv, tag(1), 1);
170
GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
171
GPR_ASSERT(0 == strcmp(details, "xyz"));
172
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
173
GPR_ASSERT(0 == strcmp(call_details.host, "foo.test.google.fr"));
174
GPR_ASSERT(was_cancelled == 1);
177
grpc_metadata_array_destroy(&initial_metadata_recv);
178
grpc_metadata_array_destroy(&trailing_metadata_recv);
179
grpc_metadata_array_destroy(&request_metadata_recv);
180
grpc_call_details_destroy(&call_details);
182
grpc_call_destroy(c);
183
grpc_call_destroy(s);
185
cq_verifier_destroy(cqv);
188
static void test_simple_delayed_request_short(grpc_end2end_test_config config) {
189
grpc_end2end_test_fixture f;
191
gpr_log(GPR_INFO, "%s/%s", "test_simple_delayed_request_short", config.name);
192
f = config.create_fixture(NULL, NULL);
193
simple_delayed_request_body(config, &f, NULL, NULL, 100000);
195
config.tear_down_data(&f);
198
static void test_simple_delayed_request_long(grpc_end2end_test_config config) {
199
grpc_end2end_test_fixture f;
201
gpr_log(GPR_INFO, "%s/%s", "test_simple_delayed_request_long", config.name);
202
f = config.create_fixture(NULL, NULL);
203
/* This timeout should be longer than a single retry */
204
simple_delayed_request_body(config, &f, NULL, NULL, 1500000);
206
config.tear_down_data(&f);
209
void grpc_end2end_tests(grpc_end2end_test_config config) {
210
if (config.feature_mask & FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION) {
211
test_simple_delayed_request_short(config);
212
test_simple_delayed_request_long(config);