aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/core/echo/echo_test.c3
-rw-r--r--test/core/end2end/cq_verifier.c44
-rw-r--r--test/core/end2end/cq_verifier.h4
-rw-r--r--test/core/end2end/dualstack_socket_test.c1
-rw-r--r--test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c21
-rwxr-xr-xtest/core/end2end/gen_build_json.py28
-rw-r--r--test/core/end2end/tests/cancel_after_accept.c103
-rw-r--r--test/core/end2end/tests/cancel_after_accept_and_writes_closed_legacy.c167
-rw-r--r--test/core/end2end/tests/cancel_after_accept_legacy.c159
-rw-r--r--test/core/end2end/tests/cancel_after_invoke.c72
-rw-r--r--test/core/end2end/tests/cancel_after_invoke_legacy.c141
-rw-r--r--test/core/end2end/tests/cancel_before_invoke.c69
-rw-r--r--test/core/end2end/tests/cancel_before_invoke_legacy.c134
-rw-r--r--test/core/end2end/tests/cancel_in_a_vacuum.c2
-rw-r--r--test/core/end2end/tests/cancel_in_a_vacuum_legacy.c131
-rw-r--r--test/core/end2end/tests/cancel_test_helpers.h2
-rw-r--r--test/core/end2end/tests/census_simple_request.c1
-rw-r--r--test/core/end2end/tests/census_simple_request_legacy.c178
-rw-r--r--test/core/end2end/tests/disappearing_server_legacy.c168
-rw-r--r--test/core/end2end/tests/early_server_shutdown_finishes_inflight_calls_legacy.c159
-rw-r--r--test/core/end2end/tests/early_server_shutdown_finishes_tags_legacy.c127
-rw-r--r--test/core/end2end/tests/graceful_server_shutdown_legacy.c160
-rw-r--r--test/core/end2end/tests/invoke_large_request_legacy.c183
-rw-r--r--test/core/end2end/tests/max_concurrent_streams.c3
-rw-r--r--test/core/end2end/tests/max_concurrent_streams_legacy.c274
-rw-r--r--test/core/end2end/tests/no_op_legacy.c109
-rw-r--r--test/core/end2end/tests/ping_pong_streaming_legacy.c203
-rw-r--r--test/core/end2end/tests/request_response_with_binary_metadata_and_payload.c198
-rw-r--r--test/core/end2end/tests/request_response_with_binary_metadata_and_payload_legacy.c222
-rw-r--r--test/core/end2end/tests/request_response_with_metadata_and_payload.c169
-rw-r--r--test/core/end2end/tests/request_response_with_metadata_and_payload_legacy.c208
-rw-r--r--test/core/end2end/tests/request_response_with_payload.c143
-rw-r--r--test/core/end2end/tests/request_response_with_payload_legacy.c208
-rw-r--r--test/core/end2end/tests/request_response_with_trailing_metadata_and_payload.c178
-rw-r--r--test/core/end2end/tests/request_response_with_trailing_metadata_and_payload_legacy.c213
-rw-r--r--test/core/end2end/tests/request_with_large_metadata.c121
-rw-r--r--test/core/end2end/tests/request_with_large_metadata_legacy.c172
-rw-r--r--test/core/end2end/tests/request_with_payload.c123
-rw-r--r--test/core/end2end/tests/request_with_payload_legacy.c172
-rw-r--r--test/core/end2end/tests/simple_delayed_request.c91
-rw-r--r--test/core/end2end/tests/simple_delayed_request_legacy.c175
-rw-r--r--test/core/end2end/tests/simple_request.c158
-rw-r--r--test/core/end2end/tests/simple_request_legacy.c232
-rw-r--r--test/core/end2end/tests/thread_stress_legacy.c324
-rw-r--r--test/core/end2end/tests/writes_done_hangs_with_pending_read_legacy.c199
-rw-r--r--test/core/fling/fling_stream_test.c3
-rw-r--r--test/core/fling/fling_test.c3
-rw-r--r--test/core/json/json_test.c3
-rw-r--r--test/core/statistics/trace_test.c71
-rw-r--r--test/core/support/env_test.c64
-rw-r--r--test/core/support/file_test.c159
-rw-r--r--test/core/surface/completion_queue_test.c27
-rw-r--r--test/cpp/interop/client.cc10
-rw-r--r--test/cpp/util/create_test_channel.cc4
54 files changed, 5738 insertions, 558 deletions
diff --git a/test/core/echo/echo_test.c b/test/core/echo/echo_test.c
index 83b83ab7ff..5450dfbef5 100644
--- a/test/core/echo/echo_test.c
+++ b/test/core/echo/echo_test.c
@@ -31,7 +31,10 @@
*
*/
+#ifndef _POSIX_SOURCE
#define _POSIX_SOURCE
+#endif
+
#include <unistd.h>
#include <assert.h>
#include <stdio.h>
diff --git a/test/core/end2end/cq_verifier.c b/test/core/end2end/cq_verifier.c
index cf3455ca6b..15dc4270d6 100644
--- a/test/core/end2end/cq_verifier.c
+++ b/test/core/end2end/cq_verifier.c
@@ -63,6 +63,7 @@ typedef struct expectation {
union {
grpc_op_error finish_accepted;
grpc_op_error write_accepted;
+ grpc_op_error op_complete;
struct {
const char *method;
const char *host;
@@ -115,6 +116,10 @@ static int has_metadata(const grpc_metadata *md, size_t count, const char *key,
return 0;
}
+int contains_metadata(grpc_metadata_array *array, const char *key, const char *value) {
+ return has_metadata(array->metadata, array->count, key, value);
+}
+
static void verify_and_destroy_metadata(metadata *md, grpc_metadata *elems,
size_t count) {
size_t i;
@@ -158,6 +163,10 @@ static int byte_buffer_eq_slice(grpc_byte_buffer *bb, gpr_slice b) {
return ok;
}
+int byte_buffer_eq_string(grpc_byte_buffer *bb, const char *str) {
+ return byte_buffer_eq_slice(bb, gpr_slice_from_copied_string(str));
+}
+
static int string_equivalent(const char *a, const char *b) {
if (a == NULL) return b == NULL || b[0] == 0;
if (b == NULL) return a[0] == 0;
@@ -173,9 +182,6 @@ static void verify_matches(expectation *e, grpc_event *ev) {
case GRPC_WRITE_ACCEPTED:
GPR_ASSERT(e->data.write_accepted == ev->data.write_accepted);
break;
- case GRPC_INVOKE_ACCEPTED:
- abort();
- break;
case GRPC_SERVER_RPC_NEW:
GPR_ASSERT(string_equivalent(e->data.server_rpc_new.method,
ev->data.server_rpc_new.method));
@@ -215,6 +221,9 @@ static void verify_matches(expectation *e, grpc_event *ev) {
GPR_ASSERT(ev->data.read == NULL);
}
break;
+ case GRPC_OP_COMPLETE:
+ GPR_ASSERT(e->data.op_complete == ev->data.op_complete);
+ break;
case GRPC_SERVER_SHUTDOWN:
break;
case GRPC_COMPLETION_DO_NOT_USE:
@@ -235,7 +244,9 @@ static void metadata_expectation(gpr_strvec *buf, metadata *md) {
gpr_asprintf(&tmp, "%c%s:%s", i ? ',' : '{', md->keys[i], md->values[i]);
gpr_strvec_add(buf, tmp);
}
- gpr_strvec_add(buf, gpr_strdup("}"));
+ if (md->count) {
+ gpr_strvec_add(buf, gpr_strdup("}"));
+ }
}
}
@@ -246,22 +257,23 @@ static void expectation_to_strvec(gpr_strvec *buf, expectation *e) {
switch (e->type) {
case GRPC_FINISH_ACCEPTED:
gpr_asprintf(&tmp, "GRPC_FINISH_ACCEPTED result=%d",
- e->data.finish_accepted);
+ e->data.finish_accepted);
gpr_strvec_add(buf, tmp);
break;
case GRPC_WRITE_ACCEPTED:
gpr_asprintf(&tmp, "GRPC_WRITE_ACCEPTED result=%d",
- e->data.write_accepted);
+ e->data.write_accepted);
gpr_strvec_add(buf, tmp);
break;
- case GRPC_INVOKE_ACCEPTED:
- gpr_strvec_add(buf, gpr_strdup("GRPC_INVOKE_ACCEPTED"));
+ case GRPC_OP_COMPLETE:
+ gpr_asprintf(&tmp, "GRPC_OP_COMPLETE result=%d", e->data.op_complete);
+ gpr_strvec_add(buf, tmp);
break;
case GRPC_SERVER_RPC_NEW:
timeout = gpr_time_sub(e->data.server_rpc_new.deadline, gpr_now());
gpr_asprintf(&tmp, "GRPC_SERVER_RPC_NEW method=%s host=%s timeout=%fsec",
- e->data.server_rpc_new.method, e->data.server_rpc_new.host,
- timeout.tv_sec + 1e-9 * timeout.tv_nsec);
+ e->data.server_rpc_new.method, e->data.server_rpc_new.host,
+ timeout.tv_sec + 1e-9 * timeout.tv_nsec);
gpr_strvec_add(buf, tmp);
break;
case GRPC_CLIENT_METADATA_READ:
@@ -270,14 +282,16 @@ static void expectation_to_strvec(gpr_strvec *buf, expectation *e) {
break;
case GRPC_FINISHED:
gpr_asprintf(&tmp, "GRPC_FINISHED status=%d details=%s ",
- e->data.finished.status, e->data.finished.details);
+ e->data.finished.status, e->data.finished.details);
gpr_strvec_add(buf, tmp);
metadata_expectation(buf, e->data.finished.metadata);
break;
case GRPC_READ:
gpr_strvec_add(buf, gpr_strdup("GRPC_READ data="));
- gpr_strvec_add(buf, gpr_hexdump((char *)GPR_SLICE_START_PTR(*e->data.read),
- GPR_SLICE_LENGTH(*e->data.read), GPR_HEXDUMP_PLAINTEXT));
+ gpr_strvec_add(
+ buf,
+ gpr_hexdump((char *)GPR_SLICE_START_PTR(*e->data.read),
+ GPR_SLICE_LENGTH(*e->data.read), GPR_HEXDUMP_PLAINTEXT));
break;
case GRPC_SERVER_SHUTDOWN:
gpr_strvec_add(buf, gpr_strdup("GRPC_SERVER_SHUTDOWN"));
@@ -411,6 +425,10 @@ void cq_expect_write_accepted(cq_verifier *v, void *tag, grpc_op_error result) {
add(v, GRPC_WRITE_ACCEPTED, tag)->data.write_accepted = result;
}
+void cq_expect_completion(cq_verifier *v, void *tag, grpc_op_error result) {
+ add(v, GRPC_OP_COMPLETE, tag)->data.op_complete = result;
+}
+
void cq_expect_finish_accepted(cq_verifier *v, void *tag,
grpc_op_error result) {
add(v, GRPC_FINISH_ACCEPTED, tag)->data.finish_accepted = result;
diff --git a/test/core/end2end/cq_verifier.h b/test/core/end2end/cq_verifier.h
index 6e031d8152..8b76bc421d 100644
--- a/test/core/end2end/cq_verifier.h
+++ b/test/core/end2end/cq_verifier.h
@@ -60,6 +60,7 @@ void cq_expect_write_accepted(cq_verifier *v, void *tag, grpc_op_error result);
void cq_expect_finish_accepted(cq_verifier *v, void *tag, grpc_op_error result);
void cq_expect_read(cq_verifier *v, void *tag, gpr_slice bytes);
void cq_expect_empty_read(cq_verifier *v, void *tag);
+void cq_expect_completion(cq_verifier *v, void *tag, grpc_op_error result);
/* *output_call is set the the server call instance */
void cq_expect_server_rpc_new(cq_verifier *v, grpc_call **output_call,
void *tag, const char *method, const char *host,
@@ -71,4 +72,7 @@ void cq_expect_finished_with_status(cq_verifier *v, void *tag,
void cq_expect_finished(cq_verifier *v, void *tag, ...);
void cq_expect_server_shutdown(cq_verifier *v, void *tag);
+int byte_buffer_eq_string(grpc_byte_buffer *byte_buffer, const char *string);
+int contains_metadata(grpc_metadata_array *array, const char *key, const char *value);
+
#endif /* __GRPC_TEST_END2END_CQ_VERIFIER_H__ */
diff --git a/test/core/end2end/dualstack_socket_test.c b/test/core/end2end/dualstack_socket_test.c
index eeb454ca58..9d893f67a1 100644
--- a/test/core/end2end/dualstack_socket_test.c
+++ b/test/core/end2end/dualstack_socket_test.c
@@ -142,7 +142,6 @@ void test_connect(const char *server_host, const char *client_host, int port,
cq_verify(v_client);
cq_expect_finish_accepted(v_server, tag(5), GRPC_OP_OK);
- cq_verify(v_server);
cq_expect_finished(v_server, tag(102), NULL);
cq_verify(v_server);
diff --git a/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c b/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c
index a70819e47e..149ac8c07b 100644
--- a/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c
+++ b/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c
@@ -39,6 +39,9 @@
#include "src/core/channel/channel_args.h"
#include "src/core/security/credentials.h"
#include "src/core/security/security_context.h"
+#include "src/core/support/env.h"
+#include "src/core/support/file.h"
+#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/host_port.h>
#include <grpc/support/log.h>
@@ -99,7 +102,7 @@ void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) {
static void chttp2_init_client_simple_ssl_secure_fullstack(
grpc_end2end_test_fixture *f, grpc_channel_args *client_args) {
grpc_credentials *ssl_creds =
- grpc_ssl_credentials_create(test_root_cert, NULL);
+ grpc_ssl_credentials_create(NULL, NULL);
grpc_arg ssl_name_override = {GRPC_ARG_STRING,
GRPC_SSL_TARGET_NAME_OVERRIDE_ARG,
{"foo.test.google.com"}};
@@ -129,8 +132,20 @@ static grpc_end2end_test_config configs[] = {
int main(int argc, char **argv) {
size_t i;
+ FILE *roots_file;
+ size_t roots_size = strlen(test_root_cert);
+ char *roots_filename;
+
grpc_test_init(argc, argv);
+ /* Set the SSL roots env var. */
+ roots_file = gpr_tmpfile("chttp2_simple_ssl_fullstack_test", &roots_filename);
+ GPR_ASSERT(roots_filename != NULL);
+ GPR_ASSERT(roots_file != NULL);
+ GPR_ASSERT(fwrite(test_root_cert, 1, roots_size, roots_file) == roots_size);
+ fclose(roots_file);
+ gpr_setenv(GRPC_DEFAULT_SSL_ROOTS_FILE_PATH_ENV_VAR, roots_filename);
+
grpc_init();
for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
@@ -139,5 +154,9 @@ int main(int argc, char **argv) {
grpc_shutdown();
+ /* Cleanup. */
+ remove(roots_filename);
+ gpr_free(roots_filename);
+
return 0;
}
diff --git a/test/core/end2end/gen_build_json.py b/test/core/end2end/gen_build_json.py
index e28dbdb85d..029a72e2c4 100755
--- a/test/core/end2end/gen_build_json.py
+++ b/test/core/end2end/gen_build_json.py
@@ -33,11 +33,37 @@ END2END_TESTS = [
'request_response_with_binary_metadata_and_payload',
'request_response_with_metadata_and_payload',
'request_response_with_payload',
- 'request_response_with_trailing_metadata_and_payload',
+ 'request_with_large_metadata',
+ 'request_with_payload',
'simple_delayed_request',
'simple_request',
'thread_stress',
'writes_done_hangs_with_pending_read',
+
+ 'cancel_after_accept_legacy',
+ 'cancel_after_accept_and_writes_closed_legacy',
+ 'cancel_after_invoke_legacy',
+ 'cancel_before_invoke_legacy',
+ 'cancel_in_a_vacuum_legacy',
+ 'census_simple_request_legacy',
+ 'disappearing_server_legacy',
+ 'early_server_shutdown_finishes_inflight_calls_legacy',
+ 'early_server_shutdown_finishes_tags_legacy',
+ 'graceful_server_shutdown_legacy',
+ 'invoke_large_request_legacy',
+ 'max_concurrent_streams_legacy',
+ 'no_op_legacy',
+ 'ping_pong_streaming_legacy',
+ 'request_response_with_binary_metadata_and_payload_legacy',
+ 'request_response_with_metadata_and_payload_legacy',
+ 'request_response_with_payload_legacy',
+ 'request_response_with_trailing_metadata_and_payload_legacy',
+ 'request_with_large_metadata_legacy',
+ 'request_with_payload_legacy',
+ 'simple_delayed_request_legacy',
+ 'simple_request_legacy',
+ 'thread_stress_legacy',
+ 'writes_done_hangs_with_pending_read_legacy',
]
diff --git a/test/core/end2end/tests/cancel_after_accept.c b/test/core/end2end/tests/cancel_after_accept.c
index f9bf9fabf4..eb26ff14f0 100644
--- a/test/core/end2end/tests/cancel_after_accept.c
+++ b/test/core/end2end/tests/cancel_after_accept.c
@@ -106,40 +106,107 @@ static void end_test(grpc_end2end_test_fixture *f) {
/* Cancel after accept, no payload */
static void test_cancel_after_accept(grpc_end2end_test_config config,
cancellation_mode mode) {
+ grpc_op ops[6];
+ grpc_op *op;
grpc_call *c;
grpc_call *s;
grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
gpr_timespec deadline = five_seconds_time();
cq_verifier *v_client = cq_verifier_create(f.client_cq);
cq_verifier *v_server = cq_verifier_create(f.server_cq);
-
- c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
+ grpc_metadata_array initial_metadata_recv;
+ grpc_metadata_array trailing_metadata_recv;
+ grpc_metadata_array request_metadata_recv;
+ grpc_call_details call_details;
+ grpc_status_code status;
+ char *details = NULL;
+ size_t details_capacity = 0;
+ grpc_byte_buffer *request_payload_recv = NULL;
+ grpc_byte_buffer *response_payload_recv = NULL;
+ gpr_slice request_payload_slice = gpr_slice_from_copied_string("hello world");
+ gpr_slice response_payload_slice = gpr_slice_from_copied_string("hello you");
+ grpc_byte_buffer *request_payload =
+ grpc_byte_buffer_create(&request_payload_slice, 1);
+ grpc_byte_buffer *response_payload =
+ grpc_byte_buffer_create(&response_payload_slice, 1);
+ int was_cancelled = 2;
+
+ c = grpc_channel_create_call(f.client, f.client_cq, "/foo", "test.google.com",
deadline);
GPR_ASSERT(c);
- GPR_ASSERT(GRPC_CALL_OK ==
- grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
-
- GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
- cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com",
- deadline, NULL);
+ grpc_metadata_array_init(&initial_metadata_recv);
+ grpc_metadata_array_init(&trailing_metadata_recv);
+ grpc_metadata_array_init(&request_metadata_recv);
+ grpc_call_details_init(&call_details);
+
+ op = ops;
+ op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
+ op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
+ op->data.recv_status_on_client.status = &status;
+ op->data.recv_status_on_client.status_details = &details;
+ op->data.recv_status_on_client.status_details_capacity = &details_capacity;
+ op++;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 0;
+ op++;
+ op->op = GRPC_OP_SEND_MESSAGE;
+ op->data.send_message = request_payload;
+ op++;
+ op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
+ op++;
+ op->op = GRPC_OP_RECV_INITIAL_METADATA;
+ op->data.recv_initial_metadata = &initial_metadata_recv;
+ op++;
+ op->op = GRPC_OP_RECV_MESSAGE;
+ op->data.recv_message = &response_payload_recv;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(c, ops, op - ops, tag(1)));
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(f.server, &s,
+ &call_details,
+ &request_metadata_recv,
+ f.server_cq, tag(2)));
+ cq_expect_completion(v_server, tag(2), GRPC_OP_OK);
cq_verify(v_server);
- GPR_ASSERT(GRPC_CALL_OK ==
- grpc_call_server_accept_old(s, f.server_cq, tag(102)));
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s, 0));
- cq_expect_client_metadata_read(v_client, tag(2), NULL);
- cq_verify(v_client);
+ op = ops;
+ op->op = GRPC_OP_RECV_MESSAGE;
+ op->data.recv_message = &request_payload_recv;
+ op++;
+ op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
+ op->data.recv_close_on_server.cancelled = &was_cancelled;
+ op++;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 0;
+ op++;
+ op->op = GRPC_OP_SEND_MESSAGE;
+ op->data.send_message = response_payload;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(s, ops, op - ops, tag(3)));
GPR_ASSERT(GRPC_CALL_OK == mode.initiate_cancel(c));
- cq_expect_finished_with_status(v_client, tag(3), mode.expect_status,
- mode.expect_details, NULL);
+ cq_expect_completion(v_server, tag(3), GRPC_OP_OK);
+ cq_verify(v_server);
+
+ cq_expect_completion(v_client, tag(1), GRPC_OP_OK);
cq_verify(v_client);
- cq_expect_finished_with_status(v_server, tag(102), GRPC_STATUS_CANCELLED,
- NULL, NULL);
- cq_verify(v_server);
+ GPR_ASSERT(status == mode.expect_status);
+ GPR_ASSERT(0 == strcmp(details, mode.expect_details));
+ GPR_ASSERT(was_cancelled == 1);
+
+ grpc_metadata_array_destroy(&initial_metadata_recv);
+ grpc_metadata_array_destroy(&trailing_metadata_recv);
+ grpc_metadata_array_destroy(&request_metadata_recv);
+ grpc_call_details_destroy(&call_details);
+
+ grpc_byte_buffer_destroy(request_payload);
+ grpc_byte_buffer_destroy(response_payload);
+ grpc_byte_buffer_destroy(request_payload_recv);
+ grpc_byte_buffer_destroy(response_payload_recv);
+ gpr_free(details);
grpc_call_destroy(c);
grpc_call_destroy(s);
diff --git a/test/core/end2end/tests/cancel_after_accept_and_writes_closed_legacy.c b/test/core/end2end/tests/cancel_after_accept_and_writes_closed_legacy.c
new file mode 100644
index 0000000000..b8a1438ca4
--- /dev/null
+++ b/test/core/end2end/tests/cancel_after_accept_and_writes_closed_legacy.c
@@ -0,0 +1,167 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <grpc/byte_buffer.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "test/core/end2end/cq_verifier.h"
+#include "test/core/end2end/tests/cancel_test_helpers.h"
+
+enum { TIMEOUT = 200000 };
+
+static void *tag(gpr_intptr t) { return (void *)t; }
+
+static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
+ const char *test_name,
+ grpc_channel_args *client_args,
+ grpc_channel_args *server_args) {
+ grpc_end2end_test_fixture f;
+ gpr_log(GPR_INFO, "%s/%s", test_name, config.name);
+ f = config.create_fixture(client_args, server_args);
+ config.init_client(&f, client_args);
+ config.init_server(&f, server_args);
+ return f;
+}
+
+static gpr_timespec n_seconds_time(int n) {
+ return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
+}
+
+static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
+
+static void drain_cq(grpc_completion_queue *cq) {
+ grpc_event *ev;
+ grpc_completion_type type;
+ do {
+ ev = grpc_completion_queue_next(cq, five_seconds_time());
+ GPR_ASSERT(ev);
+ type = ev->type;
+ grpc_event_finish(ev);
+ } while (type != GRPC_QUEUE_SHUTDOWN);
+}
+
+static void shutdown_server(grpc_end2end_test_fixture *f) {
+ if (!f->server) return;
+ grpc_server_shutdown(f->server);
+ grpc_server_destroy(f->server);
+ f->server = NULL;
+}
+
+static void shutdown_client(grpc_end2end_test_fixture *f) {
+ if (!f->client) return;
+ grpc_channel_destroy(f->client);
+ f->client = NULL;
+}
+
+static void end_test(grpc_end2end_test_fixture *f) {
+ shutdown_server(f);
+ shutdown_client(f);
+
+ grpc_completion_queue_shutdown(f->server_cq);
+ drain_cq(f->server_cq);
+ grpc_completion_queue_destroy(f->server_cq);
+ grpc_completion_queue_shutdown(f->client_cq);
+ drain_cq(f->client_cq);
+ grpc_completion_queue_destroy(f->client_cq);
+}
+
+/* Cancel after accept with a writes closed, no payload */
+static void test_cancel_after_accept_and_writes_closed(
+ grpc_end2end_test_config config, cancellation_mode mode) {
+ grpc_call *c;
+ grpc_call *s;
+ grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
+ gpr_timespec deadline = five_seconds_time();
+ cq_verifier *v_client = cq_verifier_create(f.client_cq);
+ cq_verifier *v_server = cq_verifier_create(f.server_cq);
+
+ c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
+ deadline);
+ GPR_ASSERT(c);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
+ cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com",
+ deadline, NULL);
+ cq_verify(v_server);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_server_accept_old(s, f.server_cq, tag(102)));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s, 0));
+ cq_expect_client_metadata_read(v_client, tag(2), NULL);
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(4)));
+ cq_expect_finish_accepted(v_client, tag(4), GRPC_OP_OK);
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(s, tag(101)));
+ cq_expect_empty_read(v_server, tag(101));
+ cq_verify(v_server);
+
+ GPR_ASSERT(GRPC_CALL_OK == mode.initiate_cancel(c));
+
+ cq_expect_finished_with_status(v_client, tag(3), mode.expect_status,
+ mode.expect_details, NULL);
+ cq_verify(v_client);
+
+ cq_expect_finished_with_status(v_server, tag(102), GRPC_STATUS_CANCELLED,
+ NULL, NULL);
+ cq_verify(v_server);
+
+ grpc_call_destroy(c);
+ grpc_call_destroy(s);
+
+ cq_verifier_destroy(v_client);
+ cq_verifier_destroy(v_server);
+ end_test(&f);
+ config.tear_down_data(&f);
+}
+
+void grpc_end2end_tests(grpc_end2end_test_config config) {
+ unsigned i;
+
+ for (i = 0; i < GPR_ARRAY_SIZE(cancellation_modes); i++) {
+ test_cancel_after_accept_and_writes_closed(config, cancellation_modes[i]);
+ }
+}
diff --git a/test/core/end2end/tests/cancel_after_accept_legacy.c b/test/core/end2end/tests/cancel_after_accept_legacy.c
new file mode 100644
index 0000000000..f9bf9fabf4
--- /dev/null
+++ b/test/core/end2end/tests/cancel_after_accept_legacy.c
@@ -0,0 +1,159 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <grpc/byte_buffer.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "test/core/end2end/cq_verifier.h"
+#include "test/core/end2end/tests/cancel_test_helpers.h"
+
+enum { TIMEOUT = 200000 };
+
+static void *tag(gpr_intptr t) { return (void *)t; }
+
+static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
+ const char *test_name,
+ grpc_channel_args *client_args,
+ grpc_channel_args *server_args) {
+ grpc_end2end_test_fixture f;
+ gpr_log(GPR_INFO, "%s/%s", test_name, config.name);
+ f = config.create_fixture(client_args, server_args);
+ config.init_client(&f, client_args);
+ config.init_server(&f, server_args);
+ return f;
+}
+
+static gpr_timespec n_seconds_time(int n) {
+ return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
+}
+
+static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
+
+static void drain_cq(grpc_completion_queue *cq) {
+ grpc_event *ev;
+ grpc_completion_type type;
+ do {
+ ev = grpc_completion_queue_next(cq, five_seconds_time());
+ GPR_ASSERT(ev);
+ type = ev->type;
+ grpc_event_finish(ev);
+ } while (type != GRPC_QUEUE_SHUTDOWN);
+}
+
+static void shutdown_server(grpc_end2end_test_fixture *f) {
+ if (!f->server) return;
+ grpc_server_shutdown(f->server);
+ grpc_server_destroy(f->server);
+ f->server = NULL;
+}
+
+static void shutdown_client(grpc_end2end_test_fixture *f) {
+ if (!f->client) return;
+ grpc_channel_destroy(f->client);
+ f->client = NULL;
+}
+
+static void end_test(grpc_end2end_test_fixture *f) {
+ shutdown_server(f);
+ shutdown_client(f);
+
+ grpc_completion_queue_shutdown(f->server_cq);
+ drain_cq(f->server_cq);
+ grpc_completion_queue_destroy(f->server_cq);
+ grpc_completion_queue_shutdown(f->client_cq);
+ drain_cq(f->client_cq);
+ grpc_completion_queue_destroy(f->client_cq);
+}
+
+/* Cancel after accept, no payload */
+static void test_cancel_after_accept(grpc_end2end_test_config config,
+ cancellation_mode mode) {
+ grpc_call *c;
+ grpc_call *s;
+ grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
+ gpr_timespec deadline = five_seconds_time();
+ cq_verifier *v_client = cq_verifier_create(f.client_cq);
+ cq_verifier *v_server = cq_verifier_create(f.server_cq);
+
+ c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
+ deadline);
+ GPR_ASSERT(c);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
+ cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com",
+ deadline, NULL);
+ cq_verify(v_server);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_server_accept_old(s, f.server_cq, tag(102)));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s, 0));
+ cq_expect_client_metadata_read(v_client, tag(2), NULL);
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == mode.initiate_cancel(c));
+
+ cq_expect_finished_with_status(v_client, tag(3), mode.expect_status,
+ mode.expect_details, NULL);
+ cq_verify(v_client);
+
+ cq_expect_finished_with_status(v_server, tag(102), GRPC_STATUS_CANCELLED,
+ NULL, NULL);
+ cq_verify(v_server);
+
+ grpc_call_destroy(c);
+ grpc_call_destroy(s);
+
+ cq_verifier_destroy(v_client);
+ cq_verifier_destroy(v_server);
+ end_test(&f);
+ config.tear_down_data(&f);
+}
+
+void grpc_end2end_tests(grpc_end2end_test_config config) {
+ unsigned i;
+
+ for (i = 0; i < GPR_ARRAY_SIZE(cancellation_modes); i++) {
+ test_cancel_after_accept(config, cancellation_modes[i]);
+ }
+}
diff --git a/test/core/end2end/tests/cancel_after_invoke.c b/test/core/end2end/tests/cancel_after_invoke.c
index 8b28223040..96a8186d15 100644
--- a/test/core/end2end/tests/cancel_after_invoke.c
+++ b/test/core/end2end/tests/cancel_after_invoke.c
@@ -105,26 +105,74 @@ static void end_test(grpc_end2end_test_fixture *f) {
/* Cancel after invoke, no payload */
static void test_cancel_after_invoke(grpc_end2end_test_config config,
- cancellation_mode mode) {
+ cancellation_mode mode, int test_ops) {
+ grpc_op ops[6];
+ grpc_op *op;
grpc_call *c;
grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
gpr_timespec deadline = five_seconds_time();
cq_verifier *v_client = cq_verifier_create(f.client_cq);
-
- c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
+ grpc_metadata_array initial_metadata_recv;
+ grpc_metadata_array trailing_metadata_recv;
+ grpc_metadata_array request_metadata_recv;
+ grpc_call_details call_details;
+ grpc_status_code status;
+ char *details = NULL;
+ size_t details_capacity = 0;
+ grpc_byte_buffer *response_payload_recv = NULL;
+ gpr_slice request_payload_slice = gpr_slice_from_copied_string("hello world");
+ grpc_byte_buffer *request_payload =
+ grpc_byte_buffer_create(&request_payload_slice, 1);
+
+ c = grpc_channel_create_call(f.client, f.client_cq, "/foo", "test.google.com",
deadline);
GPR_ASSERT(c);
- GPR_ASSERT(GRPC_CALL_OK ==
- grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
+ grpc_metadata_array_init(&initial_metadata_recv);
+ grpc_metadata_array_init(&trailing_metadata_recv);
+ grpc_metadata_array_init(&request_metadata_recv);
+ grpc_call_details_init(&call_details);
+
+ op = ops;
+ op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
+ op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
+ op->data.recv_status_on_client.status = &status;
+ op->data.recv_status_on_client.status_details = &details;
+ op->data.recv_status_on_client.status_details_capacity = &details_capacity;
+ op++;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 0;
+ op++;
+ op->op = GRPC_OP_SEND_MESSAGE;
+ op->data.send_message = request_payload;
+ op++;
+ op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
+ op++;
+ op->op = GRPC_OP_RECV_INITIAL_METADATA;
+ op->data.recv_initial_metadata = &initial_metadata_recv;
+ op++;
+ op->op = GRPC_OP_RECV_MESSAGE;
+ op->data.recv_message = &response_payload_recv;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(c, ops, test_ops, tag(1)));
GPR_ASSERT(GRPC_CALL_OK == mode.initiate_cancel(c));
- cq_expect_client_metadata_read(v_client, tag(2), NULL);
- cq_expect_finished_with_status(v_client, tag(3), mode.expect_status,
- mode.expect_details, NULL);
+ cq_expect_completion(v_client, tag(1), GRPC_OP_OK);
cq_verify(v_client);
+ GPR_ASSERT(status == mode.expect_status);
+ GPR_ASSERT(0 == strcmp(details, mode.expect_details));
+
+ grpc_metadata_array_destroy(&initial_metadata_recv);
+ grpc_metadata_array_destroy(&trailing_metadata_recv);
+ grpc_metadata_array_destroy(&request_metadata_recv);
+ grpc_call_details_destroy(&call_details);
+
+ grpc_byte_buffer_destroy(request_payload);
+ grpc_byte_buffer_destroy(response_payload_recv);
+ gpr_free(details);
+
grpc_call_destroy(c);
cq_verifier_destroy(v_client);
@@ -133,9 +181,11 @@ static void test_cancel_after_invoke(grpc_end2end_test_config config,
}
void grpc_end2end_tests(grpc_end2end_test_config config) {
- unsigned i;
+ unsigned i, j;
- for (i = 0; i < GPR_ARRAY_SIZE(cancellation_modes); i++) {
- test_cancel_after_invoke(config, cancellation_modes[i]);
+ for (j = 2; j < 6; j++) {
+ for (i = 0; i < GPR_ARRAY_SIZE(cancellation_modes); i++) {
+ test_cancel_after_invoke(config, cancellation_modes[i], j);
+ }
}
}
diff --git a/test/core/end2end/tests/cancel_after_invoke_legacy.c b/test/core/end2end/tests/cancel_after_invoke_legacy.c
new file mode 100644
index 0000000000..8b28223040
--- /dev/null
+++ b/test/core/end2end/tests/cancel_after_invoke_legacy.c
@@ -0,0 +1,141 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <grpc/byte_buffer.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "test/core/end2end/cq_verifier.h"
+#include "test/core/end2end/tests/cancel_test_helpers.h"
+
+enum { TIMEOUT = 200000 };
+
+static void *tag(gpr_intptr t) { return (void *)t; }
+
+static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
+ const char *test_name,
+ grpc_channel_args *client_args,
+ grpc_channel_args *server_args) {
+ grpc_end2end_test_fixture f;
+ gpr_log(GPR_INFO, "%s/%s", test_name, config.name);
+ f = config.create_fixture(client_args, server_args);
+ config.init_client(&f, client_args);
+ config.init_server(&f, server_args);
+ return f;
+}
+
+static gpr_timespec n_seconds_time(int n) {
+ return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
+}
+
+static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
+
+static void drain_cq(grpc_completion_queue *cq) {
+ grpc_event *ev;
+ grpc_completion_type type;
+ do {
+ ev = grpc_completion_queue_next(cq, five_seconds_time());
+ GPR_ASSERT(ev);
+ type = ev->type;
+ grpc_event_finish(ev);
+ } while (type != GRPC_QUEUE_SHUTDOWN);
+}
+
+static void shutdown_server(grpc_end2end_test_fixture *f) {
+ if (!f->server) return;
+ grpc_server_shutdown(f->server);
+ grpc_server_destroy(f->server);
+ f->server = NULL;
+}
+
+static void shutdown_client(grpc_end2end_test_fixture *f) {
+ if (!f->client) return;
+ grpc_channel_destroy(f->client);
+ f->client = NULL;
+}
+
+static void end_test(grpc_end2end_test_fixture *f) {
+ shutdown_server(f);
+ shutdown_client(f);
+
+ grpc_completion_queue_shutdown(f->server_cq);
+ drain_cq(f->server_cq);
+ grpc_completion_queue_destroy(f->server_cq);
+ grpc_completion_queue_shutdown(f->client_cq);
+ drain_cq(f->client_cq);
+ grpc_completion_queue_destroy(f->client_cq);
+}
+
+/* Cancel after invoke, no payload */
+static void test_cancel_after_invoke(grpc_end2end_test_config config,
+ cancellation_mode mode) {
+ grpc_call *c;
+ grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
+ gpr_timespec deadline = five_seconds_time();
+ cq_verifier *v_client = cq_verifier_create(f.client_cq);
+
+ c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
+ deadline);
+ GPR_ASSERT(c);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
+
+ GPR_ASSERT(GRPC_CALL_OK == mode.initiate_cancel(c));
+
+ cq_expect_client_metadata_read(v_client, tag(2), NULL);
+ cq_expect_finished_with_status(v_client, tag(3), mode.expect_status,
+ mode.expect_details, NULL);
+ cq_verify(v_client);
+
+ grpc_call_destroy(c);
+
+ cq_verifier_destroy(v_client);
+ end_test(&f);
+ config.tear_down_data(&f);
+}
+
+void grpc_end2end_tests(grpc_end2end_test_config config) {
+ unsigned i;
+
+ for (i = 0; i < GPR_ARRAY_SIZE(cancellation_modes); i++) {
+ test_cancel_after_invoke(config, cancellation_modes[i]);
+ }
+}
diff --git a/test/core/end2end/tests/cancel_before_invoke.c b/test/core/end2end/tests/cancel_before_invoke.c
index 5851277d20..63e7f09dd5 100644
--- a/test/core/end2end/tests/cancel_before_invoke.c
+++ b/test/core/end2end/tests/cancel_before_invoke.c
@@ -103,25 +103,73 @@ static void end_test(grpc_end2end_test_fixture *f) {
}
/* Cancel before invoke */
-static void test_cancel_before_invoke(grpc_end2end_test_config config) {
+static void test_cancel_before_invoke(grpc_end2end_test_config config, int test_ops) {
+ grpc_op ops[6];
+ grpc_op *op;
grpc_call *c;
grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
gpr_timespec deadline = five_seconds_time();
cq_verifier *v_client = cq_verifier_create(f.client_cq);
-
- c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
+ grpc_metadata_array initial_metadata_recv;
+ grpc_metadata_array trailing_metadata_recv;
+ grpc_metadata_array request_metadata_recv;
+ grpc_call_details call_details;
+ grpc_status_code status;
+ char *details = NULL;
+ size_t details_capacity = 0;
+ grpc_byte_buffer *response_payload_recv = NULL;
+ gpr_slice request_payload_slice = gpr_slice_from_copied_string("hello world");
+ grpc_byte_buffer *request_payload =
+ grpc_byte_buffer_create(&request_payload_slice, 1);
+
+ c = grpc_channel_create_call(f.client, f.client_cq, "/foo", "test.google.com",
deadline);
GPR_ASSERT(c);
GPR_ASSERT(GRPC_CALL_OK == grpc_call_cancel(c));
- GPR_ASSERT(GRPC_CALL_OK ==
- grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
- cq_expect_client_metadata_read(v_client, tag(2), NULL);
- cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_CANCELLED, NULL,
- NULL);
+ grpc_metadata_array_init(&initial_metadata_recv);
+ grpc_metadata_array_init(&trailing_metadata_recv);
+ grpc_metadata_array_init(&request_metadata_recv);
+ grpc_call_details_init(&call_details);
+
+ op = ops;
+ op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
+ op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
+ op->data.recv_status_on_client.status = &status;
+ op->data.recv_status_on_client.status_details = &details;
+ op->data.recv_status_on_client.status_details_capacity = &details_capacity;
+ op++;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 0;
+ op++;
+ op->op = GRPC_OP_SEND_MESSAGE;
+ op->data.send_message = request_payload;
+ op++;
+ op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
+ op++;
+ op->op = GRPC_OP_RECV_INITIAL_METADATA;
+ op->data.recv_initial_metadata = &initial_metadata_recv;
+ op++;
+ op->op = GRPC_OP_RECV_MESSAGE;
+ op->data.recv_message = &response_payload_recv;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(c, ops, test_ops, tag(1)));
+
+ cq_expect_completion(v_client, tag(1), GRPC_OP_OK);
cq_verify(v_client);
+ GPR_ASSERT(status == GRPC_STATUS_CANCELLED);
+
+ grpc_metadata_array_destroy(&initial_metadata_recv);
+ grpc_metadata_array_destroy(&trailing_metadata_recv);
+ grpc_metadata_array_destroy(&request_metadata_recv);
+ grpc_call_details_destroy(&call_details);
+
+ grpc_byte_buffer_destroy(request_payload);
+ grpc_byte_buffer_destroy(response_payload_recv);
+ gpr_free(details);
+
grpc_call_destroy(c);
cq_verifier_destroy(v_client);
@@ -130,5 +178,8 @@ static void test_cancel_before_invoke(grpc_end2end_test_config config) {
}
void grpc_end2end_tests(grpc_end2end_test_config config) {
- test_cancel_before_invoke(config);
+ int i;
+ for (i = 1; i <= 6; i++) {
+ test_cancel_before_invoke(config, i);
+ }
}
diff --git a/test/core/end2end/tests/cancel_before_invoke_legacy.c b/test/core/end2end/tests/cancel_before_invoke_legacy.c
new file mode 100644
index 0000000000..5851277d20
--- /dev/null
+++ b/test/core/end2end/tests/cancel_before_invoke_legacy.c
@@ -0,0 +1,134 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <grpc/byte_buffer.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "test/core/end2end/cq_verifier.h"
+
+enum { TIMEOUT = 200000 };
+
+static void *tag(gpr_intptr t) { return (void *)t; }
+
+static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
+ const char *test_name,
+ grpc_channel_args *client_args,
+ grpc_channel_args *server_args) {
+ grpc_end2end_test_fixture f;
+ gpr_log(GPR_INFO, "%s/%s", test_name, config.name);
+ f = config.create_fixture(client_args, server_args);
+ config.init_client(&f, client_args);
+ config.init_server(&f, server_args);
+ return f;
+}
+
+static gpr_timespec n_seconds_time(int n) {
+ return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
+}
+
+static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
+
+static void drain_cq(grpc_completion_queue *cq) {
+ grpc_event *ev;
+ grpc_completion_type type;
+ do {
+ ev = grpc_completion_queue_next(cq, five_seconds_time());
+ GPR_ASSERT(ev);
+ type = ev->type;
+ grpc_event_finish(ev);
+ } while (type != GRPC_QUEUE_SHUTDOWN);
+}
+
+static void shutdown_server(grpc_end2end_test_fixture *f) {
+ if (!f->server) return;
+ grpc_server_shutdown(f->server);
+ grpc_server_destroy(f->server);
+ f->server = NULL;
+}
+
+static void shutdown_client(grpc_end2end_test_fixture *f) {
+ if (!f->client) return;
+ grpc_channel_destroy(f->client);
+ f->client = NULL;
+}
+
+static void end_test(grpc_end2end_test_fixture *f) {
+ shutdown_server(f);
+ shutdown_client(f);
+
+ grpc_completion_queue_shutdown(f->server_cq);
+ drain_cq(f->server_cq);
+ grpc_completion_queue_destroy(f->server_cq);
+ grpc_completion_queue_shutdown(f->client_cq);
+ drain_cq(f->client_cq);
+ grpc_completion_queue_destroy(f->client_cq);
+}
+
+/* Cancel before invoke */
+static void test_cancel_before_invoke(grpc_end2end_test_config config) {
+ grpc_call *c;
+ grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
+ gpr_timespec deadline = five_seconds_time();
+ cq_verifier *v_client = cq_verifier_create(f.client_cq);
+
+ c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
+ deadline);
+ GPR_ASSERT(c);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_cancel(c));
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
+ cq_expect_client_metadata_read(v_client, tag(2), NULL);
+ cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_CANCELLED, NULL,
+ NULL);
+ cq_verify(v_client);
+
+ grpc_call_destroy(c);
+
+ cq_verifier_destroy(v_client);
+ end_test(&f);
+ config.tear_down_data(&f);
+}
+
+void grpc_end2end_tests(grpc_end2end_test_config config) {
+ test_cancel_before_invoke(config);
+}
diff --git a/test/core/end2end/tests/cancel_in_a_vacuum.c b/test/core/end2end/tests/cancel_in_a_vacuum.c
index 6b5194fb07..e493941f0a 100644
--- a/test/core/end2end/tests/cancel_in_a_vacuum.c
+++ b/test/core/end2end/tests/cancel_in_a_vacuum.c
@@ -109,7 +109,7 @@ static void test_cancel_in_a_vacuum(grpc_end2end_test_config config,
gpr_timespec deadline = five_seconds_time();
cq_verifier *v_client = cq_verifier_create(f.client_cq);
- c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
+ c = grpc_channel_create_call(f.client, f.client_cq, "/foo", "test.google.com",
deadline);
GPR_ASSERT(c);
diff --git a/test/core/end2end/tests/cancel_in_a_vacuum_legacy.c b/test/core/end2end/tests/cancel_in_a_vacuum_legacy.c
new file mode 100644
index 0000000000..6b5194fb07
--- /dev/null
+++ b/test/core/end2end/tests/cancel_in_a_vacuum_legacy.c
@@ -0,0 +1,131 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <grpc/byte_buffer.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "test/core/end2end/cq_verifier.h"
+#include "test/core/end2end/tests/cancel_test_helpers.h"
+
+enum { TIMEOUT = 200000 };
+
+static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
+ const char *test_name,
+ grpc_channel_args *client_args,
+ grpc_channel_args *server_args) {
+ grpc_end2end_test_fixture f;
+ gpr_log(GPR_INFO, "%s/%s", test_name, config.name);
+ f = config.create_fixture(client_args, server_args);
+ config.init_client(&f, client_args);
+ config.init_server(&f, server_args);
+ return f;
+}
+
+static gpr_timespec n_seconds_time(int n) {
+ return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
+}
+
+static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
+
+static void drain_cq(grpc_completion_queue *cq) {
+ grpc_event *ev;
+ grpc_completion_type type;
+ do {
+ ev = grpc_completion_queue_next(cq, five_seconds_time());
+ GPR_ASSERT(ev);
+ type = ev->type;
+ grpc_event_finish(ev);
+ } while (type != GRPC_QUEUE_SHUTDOWN);
+}
+
+static void shutdown_server(grpc_end2end_test_fixture *f) {
+ if (!f->server) return;
+ grpc_server_shutdown(f->server);
+ grpc_server_destroy(f->server);
+ f->server = NULL;
+}
+
+static void shutdown_client(grpc_end2end_test_fixture *f) {
+ if (!f->client) return;
+ grpc_channel_destroy(f->client);
+ f->client = NULL;
+}
+
+static void end_test(grpc_end2end_test_fixture *f) {
+ shutdown_server(f);
+ shutdown_client(f);
+
+ grpc_completion_queue_shutdown(f->server_cq);
+ drain_cq(f->server_cq);
+ grpc_completion_queue_destroy(f->server_cq);
+ grpc_completion_queue_shutdown(f->client_cq);
+ drain_cq(f->client_cq);
+ grpc_completion_queue_destroy(f->client_cq);
+}
+
+/* Cancel and do nothing */
+static void test_cancel_in_a_vacuum(grpc_end2end_test_config config,
+ cancellation_mode mode) {
+ grpc_call *c;
+ grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
+ gpr_timespec deadline = five_seconds_time();
+ cq_verifier *v_client = cq_verifier_create(f.client_cq);
+
+ c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
+ deadline);
+ GPR_ASSERT(c);
+
+ GPR_ASSERT(GRPC_CALL_OK == mode.initiate_cancel(c));
+
+ grpc_call_destroy(c);
+
+ cq_verifier_destroy(v_client);
+ end_test(&f);
+ config.tear_down_data(&f);
+}
+
+void grpc_end2end_tests(grpc_end2end_test_config config) {
+ unsigned i;
+
+ for (i = 0; i < GPR_ARRAY_SIZE(cancellation_modes); i++) {
+ test_cancel_in_a_vacuum(config, cancellation_modes[i]);
+ }
+}
diff --git a/test/core/end2end/tests/cancel_test_helpers.h b/test/core/end2end/tests/cancel_test_helpers.h
index 35c81fa792..52ebc9052f 100644
--- a/test/core/end2end/tests/cancel_test_helpers.h
+++ b/test/core/end2end/tests/cancel_test_helpers.h
@@ -45,7 +45,7 @@ static grpc_call_error wait_for_deadline(grpc_call *call) {
}
static const cancellation_mode cancellation_modes[] = {
- {grpc_call_cancel, GRPC_STATUS_CANCELLED, NULL},
+ {grpc_call_cancel, GRPC_STATUS_CANCELLED, ""},
{wait_for_deadline, GRPC_STATUS_DEADLINE_EXCEEDED, "Deadline Exceeded"}, };
#endif
diff --git a/test/core/end2end/tests/census_simple_request.c b/test/core/end2end/tests/census_simple_request.c
index 1edb5b0d3a..4cbaa65b32 100644
--- a/test/core/end2end/tests/census_simple_request.c
+++ b/test/core/end2end/tests/census_simple_request.c
@@ -135,7 +135,6 @@ static void test_body(grpc_end2end_test_fixture f) {
cq_verify(v_client);
cq_expect_finish_accepted(v_server, tag(5), GRPC_OP_OK);
- cq_verify(v_server);
cq_expect_finished(v_server, tag(102), NULL);
cq_verify(v_server);
grpc_call_destroy(c);
diff --git a/test/core/end2end/tests/census_simple_request_legacy.c b/test/core/end2end/tests/census_simple_request_legacy.c
new file mode 100644
index 0000000000..4cbaa65b32
--- /dev/null
+++ b/test/core/end2end/tests/census_simple_request_legacy.c
@@ -0,0 +1,178 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "src/core/support/string.h"
+#include <grpc/byte_buffer.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "test/core/end2end/cq_verifier.h"
+
+static gpr_timespec n_seconds_time(int n) {
+ return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
+}
+
+static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
+ const char *test_name,
+ grpc_channel_args *client_args,
+ grpc_channel_args *server_args) {
+ grpc_end2end_test_fixture f;
+ gpr_log(GPR_INFO, "%s/%s", test_name, config.name);
+ f = config.create_fixture(client_args, server_args);
+ config.init_client(&f, client_args);
+ config.init_server(&f, server_args);
+ return f;
+}
+
+static void shutdown_server(grpc_end2end_test_fixture *f) {
+ if (!f->server) return;
+ grpc_server_shutdown(f->server);
+ grpc_server_destroy(f->server);
+ f->server = NULL;
+}
+
+static void shutdown_client(grpc_end2end_test_fixture *f) {
+ if (!f->client) return;
+ grpc_channel_destroy(f->client);
+ f->client = NULL;
+}
+
+static void drain_cq(grpc_completion_queue *cq) {
+ grpc_event *ev;
+ grpc_completion_type type;
+ do {
+ ev = grpc_completion_queue_next(cq, n_seconds_time(5));
+ GPR_ASSERT(ev);
+ type = ev->type;
+ grpc_event_finish(ev);
+ } while (type != GRPC_QUEUE_SHUTDOWN);
+}
+
+static void end_test(grpc_end2end_test_fixture *f) {
+ shutdown_server(f);
+ shutdown_client(f);
+
+ grpc_completion_queue_shutdown(f->server_cq);
+ drain_cq(f->server_cq);
+ grpc_completion_queue_destroy(f->server_cq);
+ grpc_completion_queue_shutdown(f->client_cq);
+ drain_cq(f->client_cq);
+ grpc_completion_queue_destroy(f->client_cq);
+}
+
+static void *tag(gpr_intptr t) { return (void *)t; }
+
+static void test_body(grpc_end2end_test_fixture f) {
+ grpc_call *c;
+ grpc_call *s;
+ gpr_timespec deadline = n_seconds_time(10);
+ cq_verifier *v_client = cq_verifier_create(f.client_cq);
+ cq_verifier *v_server = cq_verifier_create(f.server_cq);
+
+ c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
+ deadline);
+ GPR_ASSERT(c);
+ tag(1);
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(4)));
+ cq_expect_finish_accepted(v_client, tag(4), GRPC_OP_OK);
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
+ cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com",
+ deadline, NULL);
+ cq_verify(v_server);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_server_accept_old(s, f.server_cq, tag(102)));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s, 0));
+ cq_expect_client_metadata_read(v_client, tag(2), NULL);
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_status_old(
+ s, GRPC_STATUS_UNIMPLEMENTED, "xyz", tag(5)));
+ cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_UNIMPLEMENTED,
+ "xyz", NULL);
+ cq_verify(v_client);
+
+ cq_expect_finish_accepted(v_server, tag(5), GRPC_OP_OK);
+ cq_expect_finished(v_server, tag(102), NULL);
+ cq_verify(v_server);
+ grpc_call_destroy(c);
+ grpc_call_destroy(s);
+
+ cq_verifier_destroy(v_client);
+ cq_verifier_destroy(v_server);
+}
+
+static void test_invoke_request_with_census(
+ grpc_end2end_test_config config, const char *name,
+ void (*body)(grpc_end2end_test_fixture f)) {
+ char *fullname;
+ grpc_end2end_test_fixture f;
+ grpc_arg client_arg, server_arg;
+ grpc_channel_args client_args, server_args;
+
+ client_arg.type = GRPC_ARG_INTEGER;
+ client_arg.key = GRPC_ARG_ENABLE_CENSUS;
+ client_arg.value.integer = 1;
+
+ client_args.num_args = 1;
+ client_args.args = &client_arg;
+
+ server_arg.type = GRPC_ARG_INTEGER;
+ server_arg.key = GRPC_ARG_ENABLE_CENSUS;
+ server_arg.value.integer = 1;
+ server_args.num_args = 1;
+ server_args.args = &server_arg;
+
+ gpr_asprintf(&fullname, "%s/%s", __FUNCTION__, name);
+ f = begin_test(config, fullname, &client_args, &server_args);
+ body(f);
+ end_test(&f);
+ config.tear_down_data(&f);
+ gpr_free(fullname);
+}
+
+void grpc_end2end_tests(grpc_end2end_test_config config) {
+ test_invoke_request_with_census(config, "census_simple_request", test_body);
+}
diff --git a/test/core/end2end/tests/disappearing_server_legacy.c b/test/core/end2end/tests/disappearing_server_legacy.c
new file mode 100644
index 0000000000..9b2f16890b
--- /dev/null
+++ b/test/core/end2end/tests/disappearing_server_legacy.c
@@ -0,0 +1,168 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <grpc/byte_buffer.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "test/core/end2end/cq_verifier.h"
+
+enum { TIMEOUT = 200000 };
+
+static void *tag(gpr_intptr t) { return (void *)t; }
+
+static gpr_timespec n_seconds_time(int n) {
+ return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
+}
+
+static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
+
+static void drain_cq(grpc_completion_queue *cq) {
+ grpc_event *ev;
+ grpc_completion_type type;
+ do {
+ ev = grpc_completion_queue_next(cq, five_seconds_time());
+ GPR_ASSERT(ev);
+ type = ev->type;
+ grpc_event_finish(ev);
+ } while (type != GRPC_QUEUE_SHUTDOWN);
+}
+
+static void shutdown_server(grpc_end2end_test_fixture *f) {
+ if (!f->server) return;
+ grpc_server_shutdown(f->server);
+ grpc_server_destroy(f->server);
+ f->server = NULL;
+}
+
+static void shutdown_client(grpc_end2end_test_fixture *f) {
+ if (!f->client) return;
+ grpc_channel_destroy(f->client);
+ f->client = NULL;
+}
+
+static void end_test(grpc_end2end_test_fixture *f) {
+ shutdown_server(f);
+ shutdown_client(f);
+
+ grpc_completion_queue_shutdown(f->server_cq);
+ drain_cq(f->server_cq);
+ grpc_completion_queue_destroy(f->server_cq);
+ grpc_completion_queue_shutdown(f->client_cq);
+ drain_cq(f->client_cq);
+ grpc_completion_queue_destroy(f->client_cq);
+}
+
+static void do_request_and_shutdown_server(grpc_end2end_test_fixture *f,
+ cq_verifier *v_client,
+ cq_verifier *v_server) {
+ grpc_call *c;
+ grpc_call *s;
+ gpr_timespec deadline = five_seconds_time();
+
+ c = grpc_channel_create_call_old(f->client, "/foo", "test.google.com",
+ deadline);
+ GPR_ASSERT(c);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_invoke_old(c, f->client_cq, tag(2), tag(3), 0));
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(4)));
+ cq_expect_finish_accepted(v_client, tag(4), GRPC_OP_OK);
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f->server, tag(100)));
+ cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com",
+ deadline, NULL);
+ cq_verify(v_server);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_server_accept_old(s, f->server_cq, tag(102)));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s, 0));
+ cq_expect_client_metadata_read(v_client, tag(2), NULL);
+ cq_verify(v_client);
+
+ /* should be able to shut down the server early
+ - and still complete the request */
+ grpc_server_shutdown(f->server);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_status_old(
+ s, GRPC_STATUS_UNIMPLEMENTED, "xyz", tag(5)));
+ cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_UNIMPLEMENTED,
+ "xyz", NULL);
+ cq_verify(v_client);
+
+ cq_expect_finish_accepted(v_server, tag(5), GRPC_OP_OK);
+ cq_expect_finished(v_server, tag(102), NULL);
+ cq_verify(v_server);
+
+ grpc_call_destroy(c);
+ grpc_call_destroy(s);
+}
+
+static void disappearing_server_test(grpc_end2end_test_config config) {
+ grpc_end2end_test_fixture f = config.create_fixture(NULL, NULL);
+ cq_verifier *v_client = cq_verifier_create(f.client_cq);
+ cq_verifier *v_server = cq_verifier_create(f.server_cq);
+
+ gpr_log(GPR_INFO, "%s/%s", __FUNCTION__, config.name);
+
+ config.init_client(&f, NULL);
+ config.init_server(&f, NULL);
+
+ do_request_and_shutdown_server(&f, v_client, v_server);
+
+ /* now destroy and recreate the server */
+ config.init_server(&f, NULL);
+
+ do_request_and_shutdown_server(&f, v_client, v_server);
+
+ cq_verifier_destroy(v_client);
+ cq_verifier_destroy(v_server);
+
+ end_test(&f);
+ config.tear_down_data(&f);
+}
+
+void grpc_end2end_tests(grpc_end2end_test_config config) {
+ if (config.feature_mask & FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION) {
+ disappearing_server_test(config);
+ }
+}
diff --git a/test/core/end2end/tests/early_server_shutdown_finishes_inflight_calls_legacy.c b/test/core/end2end/tests/early_server_shutdown_finishes_inflight_calls_legacy.c
new file mode 100644
index 0000000000..a9d34e2db5
--- /dev/null
+++ b/test/core/end2end/tests/early_server_shutdown_finishes_inflight_calls_legacy.c
@@ -0,0 +1,159 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <grpc/byte_buffer.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "test/core/end2end/cq_verifier.h"
+
+enum { TIMEOUT = 200000 };
+
+static void *tag(gpr_intptr t) { return (void *)t; }
+
+static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
+ const char *test_name,
+ grpc_channel_args *client_args,
+ grpc_channel_args *server_args) {
+ grpc_end2end_test_fixture f;
+ gpr_log(GPR_INFO, "%s/%s", test_name, config.name);
+ f = config.create_fixture(client_args, server_args);
+ config.init_client(&f, client_args);
+ config.init_server(&f, server_args);
+ return f;
+}
+
+static gpr_timespec n_seconds_time(int n) {
+ return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
+}
+
+static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
+
+static void drain_cq(grpc_completion_queue *cq) {
+ grpc_event *ev;
+ grpc_completion_type type;
+ do {
+ ev = grpc_completion_queue_next(cq, five_seconds_time());
+ GPR_ASSERT(ev);
+ type = ev->type;
+ grpc_event_finish(ev);
+ } while (type != GRPC_QUEUE_SHUTDOWN);
+}
+
+static void shutdown_server(grpc_end2end_test_fixture *f) {
+ if (!f->server) return;
+ grpc_server_shutdown(f->server);
+ grpc_server_destroy(f->server);
+ f->server = NULL;
+}
+
+static void shutdown_client(grpc_end2end_test_fixture *f) {
+ if (!f->client) return;
+ grpc_channel_destroy(f->client);
+ f->client = NULL;
+}
+
+static void end_test(grpc_end2end_test_fixture *f) {
+ shutdown_server(f);
+ shutdown_client(f);
+
+ grpc_completion_queue_shutdown(f->server_cq);
+ drain_cq(f->server_cq);
+ grpc_completion_queue_destroy(f->server_cq);
+ grpc_completion_queue_shutdown(f->client_cq);
+ drain_cq(f->client_cq);
+ grpc_completion_queue_destroy(f->client_cq);
+}
+
+static void test_early_server_shutdown_finishes_inflight_calls(
+ grpc_end2end_test_config config) {
+ grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
+ grpc_call *c;
+ grpc_call *s;
+ gpr_timespec deadline = five_seconds_time();
+ cq_verifier *v_client = cq_verifier_create(f.client_cq);
+ cq_verifier *v_server = cq_verifier_create(f.server_cq);
+
+ c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
+ deadline);
+ GPR_ASSERT(c);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(4)));
+ cq_expect_finish_accepted(v_client, tag(4), GRPC_OP_OK);
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
+ cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com",
+ deadline, NULL);
+ cq_verify(v_server);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_server_accept_old(s, f.server_cq, tag(102)));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s, 0));
+ cq_expect_client_metadata_read(v_client, tag(2), NULL);
+ cq_verify(v_client);
+
+ /* shutdown and destroy the server */
+ shutdown_server(&f);
+
+ cq_expect_finished(v_server, tag(102), NULL);
+ cq_verify(v_server);
+
+ grpc_call_destroy(s);
+
+ cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_UNAVAILABLE,
+ NULL, NULL);
+ cq_verify(v_client);
+
+ grpc_call_destroy(c);
+
+ cq_verifier_destroy(v_client);
+ cq_verifier_destroy(v_server);
+
+ end_test(&f);
+ config.tear_down_data(&f);
+}
+
+void grpc_end2end_tests(grpc_end2end_test_config config) {
+ test_early_server_shutdown_finishes_inflight_calls(config);
+}
diff --git a/test/core/end2end/tests/early_server_shutdown_finishes_tags_legacy.c b/test/core/end2end/tests/early_server_shutdown_finishes_tags_legacy.c
new file mode 100644
index 0000000000..123c8bc415
--- /dev/null
+++ b/test/core/end2end/tests/early_server_shutdown_finishes_tags_legacy.c
@@ -0,0 +1,127 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <grpc/byte_buffer.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "test/core/end2end/cq_verifier.h"
+
+enum { TIMEOUT = 200000 };
+
+static void *tag(gpr_intptr t) { return (void *)t; }
+
+static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
+ const char *test_name,
+ grpc_channel_args *client_args,
+ grpc_channel_args *server_args) {
+ grpc_end2end_test_fixture f;
+ gpr_log(GPR_INFO, "%s/%s", test_name, config.name);
+ f = config.create_fixture(client_args, server_args);
+ config.init_client(&f, client_args);
+ config.init_server(&f, server_args);
+ return f;
+}
+
+static gpr_timespec n_seconds_time(int n) {
+ return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
+}
+
+static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
+
+static void drain_cq(grpc_completion_queue *cq) {
+ grpc_event *ev;
+ grpc_completion_type type;
+ do {
+ ev = grpc_completion_queue_next(cq, five_seconds_time());
+ GPR_ASSERT(ev);
+ type = ev->type;
+ grpc_event_finish(ev);
+ } while (type != GRPC_QUEUE_SHUTDOWN);
+}
+
+static void shutdown_server(grpc_end2end_test_fixture *f) {
+ if (!f->server) return;
+ grpc_server_shutdown(f->server);
+ grpc_server_destroy(f->server);
+ f->server = NULL;
+}
+
+static void shutdown_client(grpc_end2end_test_fixture *f) {
+ if (!f->client) return;
+ grpc_channel_destroy(f->client);
+ f->client = NULL;
+}
+
+static void end_test(grpc_end2end_test_fixture *f) {
+ shutdown_server(f);
+ shutdown_client(f);
+
+ grpc_completion_queue_shutdown(f->server_cq);
+ drain_cq(f->server_cq);
+ grpc_completion_queue_destroy(f->server_cq);
+ grpc_completion_queue_shutdown(f->client_cq);
+ drain_cq(f->client_cq);
+ grpc_completion_queue_destroy(f->client_cq);
+}
+
+static void test_early_server_shutdown_finishes_tags(
+ grpc_end2end_test_config config) {
+ grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
+ cq_verifier *v_server = cq_verifier_create(f.server_cq);
+ grpc_call *s = (void *)1;
+
+ /* upon shutdown, the server should finish all requested calls indicating
+ no new call */
+ grpc_server_request_call_old(f.server, tag(1000));
+ grpc_server_shutdown(f.server);
+ cq_expect_server_rpc_new(v_server, &s, tag(1000), NULL, NULL, gpr_inf_past,
+ NULL);
+ cq_verify(v_server);
+ GPR_ASSERT(s == NULL);
+
+ end_test(&f);
+ config.tear_down_data(&f);
+ cq_verifier_destroy(v_server);
+}
+
+void grpc_end2end_tests(grpc_end2end_test_config config) {
+ test_early_server_shutdown_finishes_tags(config);
+}
diff --git a/test/core/end2end/tests/graceful_server_shutdown_legacy.c b/test/core/end2end/tests/graceful_server_shutdown_legacy.c
new file mode 100644
index 0000000000..dcd6192799
--- /dev/null
+++ b/test/core/end2end/tests/graceful_server_shutdown_legacy.c
@@ -0,0 +1,160 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <grpc/byte_buffer.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "test/core/end2end/cq_verifier.h"
+
+enum { TIMEOUT = 200000 };
+
+static void *tag(gpr_intptr t) { return (void *)t; }
+
+static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
+ const char *test_name,
+ grpc_channel_args *client_args,
+ grpc_channel_args *server_args) {
+ grpc_end2end_test_fixture f;
+ gpr_log(GPR_INFO, "%s/%s", test_name, config.name);
+ f = config.create_fixture(client_args, server_args);
+ config.init_client(&f, client_args);
+ config.init_server(&f, server_args);
+ return f;
+}
+
+static gpr_timespec n_seconds_time(int n) {
+ return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
+}
+
+static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
+
+static void drain_cq(grpc_completion_queue *cq) {
+ grpc_event *ev;
+ grpc_completion_type type;
+ do {
+ ev = grpc_completion_queue_next(cq, five_seconds_time());
+ GPR_ASSERT(ev);
+ type = ev->type;
+ grpc_event_finish(ev);
+ } while (type != GRPC_QUEUE_SHUTDOWN);
+}
+
+static void shutdown_server(grpc_end2end_test_fixture *f) {
+ if (!f->server) return;
+ grpc_server_destroy(f->server);
+ f->server = NULL;
+}
+
+static void shutdown_client(grpc_end2end_test_fixture *f) {
+ if (!f->client) return;
+ grpc_channel_destroy(f->client);
+ f->client = NULL;
+}
+
+static void end_test(grpc_end2end_test_fixture *f) {
+ shutdown_server(f);
+ shutdown_client(f);
+
+ grpc_completion_queue_shutdown(f->server_cq);
+ drain_cq(f->server_cq);
+ grpc_completion_queue_destroy(f->server_cq);
+ grpc_completion_queue_shutdown(f->client_cq);
+ drain_cq(f->client_cq);
+ grpc_completion_queue_destroy(f->client_cq);
+}
+
+static void test_early_server_shutdown_finishes_inflight_calls(
+ grpc_end2end_test_config config) {
+ grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
+ grpc_call *c;
+ grpc_call *s;
+ gpr_timespec deadline = five_seconds_time();
+ cq_verifier *v_client = cq_verifier_create(f.client_cq);
+ cq_verifier *v_server = cq_verifier_create(f.server_cq);
+
+ c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
+ deadline);
+ GPR_ASSERT(c);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(4)));
+ cq_expect_finish_accepted(v_client, tag(4), GRPC_OP_OK);
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
+ cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com",
+ deadline, NULL);
+ cq_verify(v_server);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_server_accept_old(s, f.server_cq, tag(102)));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s, 0));
+ cq_expect_client_metadata_read(v_client, tag(2), NULL);
+ cq_verify(v_client);
+
+ /* shutdown the server */
+ grpc_server_shutdown_and_notify(f.server, tag(0xdead));
+ cq_verify_empty(v_server);
+
+ grpc_call_start_write_status_old(s, GRPC_STATUS_OK, NULL, tag(103));
+ grpc_call_destroy(s);
+ cq_expect_finish_accepted(v_server, tag(103), GRPC_OP_OK);
+ cq_expect_finished(v_server, tag(102), NULL);
+ cq_expect_server_shutdown(v_server, tag(0xdead));
+ cq_verify(v_server);
+
+ cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_OK, NULL, NULL);
+ cq_verify(v_client);
+
+ grpc_call_destroy(c);
+
+ cq_verifier_destroy(v_client);
+ cq_verifier_destroy(v_server);
+
+ end_test(&f);
+ config.tear_down_data(&f);
+}
+
+void grpc_end2end_tests(grpc_end2end_test_config config) {
+ test_early_server_shutdown_finishes_inflight_calls(config);
+}
diff --git a/test/core/end2end/tests/invoke_large_request_legacy.c b/test/core/end2end/tests/invoke_large_request_legacy.c
new file mode 100644
index 0000000000..7774fe4521
--- /dev/null
+++ b/test/core/end2end/tests/invoke_large_request_legacy.c
@@ -0,0 +1,183 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <grpc/byte_buffer.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "test/core/end2end/cq_verifier.h"
+
+enum { TIMEOUT = 200000 };
+
+static void *tag(gpr_intptr t) { return (void *)t; }
+
+static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
+ const char *test_name,
+ grpc_channel_args *client_args,
+ grpc_channel_args *server_args) {
+ grpc_end2end_test_fixture f;
+ gpr_log(GPR_INFO, "%s/%s", test_name, config.name);
+ f = config.create_fixture(client_args, server_args);
+ config.init_client(&f, client_args);
+ config.init_server(&f, server_args);
+ return f;
+}
+
+static gpr_timespec n_seconds_time(int n) {
+ return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
+}
+
+static void drain_cq(grpc_completion_queue *cq) {
+ grpc_event *ev;
+ grpc_completion_type type;
+ do {
+ ev = grpc_completion_queue_next(cq, n_seconds_time(5));
+ GPR_ASSERT(ev);
+ type = ev->type;
+ grpc_event_finish(ev);
+ } while (type != GRPC_QUEUE_SHUTDOWN);
+}
+
+static void shutdown_server(grpc_end2end_test_fixture *f) {
+ if (!f->server) return;
+ grpc_server_shutdown(f->server);
+ grpc_server_destroy(f->server);
+ f->server = NULL;
+}
+
+static void shutdown_client(grpc_end2end_test_fixture *f) {
+ if (!f->client) return;
+ grpc_channel_destroy(f->client);
+ f->client = NULL;
+}
+
+static void end_test(grpc_end2end_test_fixture *f) {
+ shutdown_server(f);
+ shutdown_client(f);
+
+ grpc_completion_queue_shutdown(f->server_cq);
+ drain_cq(f->server_cq);
+ grpc_completion_queue_destroy(f->server_cq);
+ grpc_completion_queue_shutdown(f->client_cq);
+ drain_cq(f->client_cq);
+ grpc_completion_queue_destroy(f->client_cq);
+}
+
+static gpr_slice large_slice(void) {
+ gpr_slice slice = gpr_slice_malloc(1000000);
+ memset(GPR_SLICE_START_PTR(slice), 0xab, GPR_SLICE_LENGTH(slice));
+ return slice;
+}
+
+static void test_invoke_large_request(grpc_end2end_test_config config) {
+ grpc_call *c;
+ grpc_call *s;
+ gpr_slice request_payload_slice = large_slice();
+ grpc_byte_buffer *request_payload =
+ grpc_byte_buffer_create(&request_payload_slice, 1);
+ gpr_timespec deadline = n_seconds_time(30);
+ grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
+ cq_verifier *v_client = cq_verifier_create(f.client_cq);
+ cq_verifier *v_server = cq_verifier_create(f.server_cq);
+
+ /* byte buffer holds the slice, we can unref it already */
+ gpr_slice_unref(request_payload_slice);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
+
+ c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
+ deadline);
+ GPR_ASSERT(c);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_start_write_old(c, request_payload, tag(4), 0));
+ /* destroy byte buffer early to ensure async code keeps track of its contents
+ correctly */
+ grpc_byte_buffer_destroy(request_payload);
+ /* write should not be accepted until the server is willing to read the
+ request (as this request is very large) */
+ cq_verify_empty(v_client);
+
+ cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com",
+ deadline, NULL);
+ cq_verify(v_server);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_server_accept_old(s, f.server_cq, tag(102)));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s, 0));
+ cq_expect_client_metadata_read(v_client, tag(2), NULL);
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(s, tag(5)));
+ /* now the write can be accepted */
+ cq_expect_write_accepted(v_client, tag(4), GRPC_OP_OK);
+ cq_verify(v_client);
+ cq_expect_read(v_server, tag(5), large_slice());
+ cq_verify(v_server);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(8)));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_status_old(
+ s, GRPC_STATUS_UNIMPLEMENTED, "xyz", tag(9)));
+
+ cq_expect_finish_accepted(v_client, tag(8), GRPC_OP_OK);
+ cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_UNIMPLEMENTED,
+ "xyz", NULL);
+ cq_verify(v_client);
+
+ cq_expect_finish_accepted(v_server, tag(9), GRPC_OP_OK);
+ cq_expect_finished(v_server, tag(102), NULL);
+ cq_verify(v_server);
+
+ grpc_call_destroy(c);
+ grpc_call_destroy(s);
+
+ cq_verifier_destroy(v_client);
+ cq_verifier_destroy(v_server);
+
+ end_test(&f);
+ config.tear_down_data(&f);
+}
+
+void grpc_end2end_tests(grpc_end2end_test_config config) {
+ test_invoke_large_request(config);
+}
diff --git a/test/core/end2end/tests/max_concurrent_streams.c b/test/core/end2end/tests/max_concurrent_streams.c
index 0e26577903..4830b85f9b 100644
--- a/test/core/end2end/tests/max_concurrent_streams.c
+++ b/test/core/end2end/tests/max_concurrent_streams.c
@@ -138,7 +138,6 @@ static void simple_request_body(grpc_end2end_test_fixture f) {
cq_verify(v_client);
cq_expect_finish_accepted(v_server, tag(5), GRPC_OP_OK);
- cq_verify(v_server);
cq_expect_finished(v_server, tag(102), NULL);
cq_verify(v_server);
@@ -207,7 +206,7 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) {
/* The /alpha or /beta calls started above could be invoked (but NOT both);
* check this here */
/* We'll get tag 303 or 403, we want 300, 400 */
- live_call = ((int)(gpr_intptr)ev->tag) - 3;
+ live_call = ((int)(gpr_intptr) ev->tag) - 3;
grpc_event_finish(ev);
cq_expect_server_rpc_new(v_server, &s1, tag(100),
diff --git a/test/core/end2end/tests/max_concurrent_streams_legacy.c b/test/core/end2end/tests/max_concurrent_streams_legacy.c
new file mode 100644
index 0000000000..4830b85f9b
--- /dev/null
+++ b/test/core/end2end/tests/max_concurrent_streams_legacy.c
@@ -0,0 +1,274 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <grpc/byte_buffer.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "test/core/end2end/cq_verifier.h"
+
+enum { TIMEOUT = 200000 };
+
+static void *tag(gpr_intptr t) { return (void *)t; }
+
+static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
+ const char *test_name,
+ grpc_channel_args *client_args,
+ grpc_channel_args *server_args) {
+ grpc_end2end_test_fixture f;
+ gpr_log(GPR_INFO, "%s/%s", test_name, config.name);
+ f = config.create_fixture(client_args, server_args);
+ config.init_client(&f, client_args);
+ config.init_server(&f, server_args);
+ return f;
+}
+
+static gpr_timespec n_seconds_time(int n) {
+ return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
+}
+
+static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
+
+static void drain_cq(grpc_completion_queue *cq) {
+ grpc_event *ev;
+ grpc_completion_type type;
+ do {
+ ev = grpc_completion_queue_next(cq, five_seconds_time());
+ GPR_ASSERT(ev);
+ type = ev->type;
+ grpc_event_finish(ev);
+ } while (type != GRPC_QUEUE_SHUTDOWN);
+}
+
+static void shutdown_server(grpc_end2end_test_fixture *f) {
+ if (!f->server) return;
+ grpc_server_shutdown(f->server);
+ grpc_server_destroy(f->server);
+ f->server = NULL;
+}
+
+static void shutdown_client(grpc_end2end_test_fixture *f) {
+ if (!f->client) return;
+ grpc_channel_destroy(f->client);
+ f->client = NULL;
+}
+
+static void end_test(grpc_end2end_test_fixture *f) {
+ shutdown_server(f);
+ shutdown_client(f);
+
+ grpc_completion_queue_shutdown(f->server_cq);
+ drain_cq(f->server_cq);
+ grpc_completion_queue_destroy(f->server_cq);
+ grpc_completion_queue_shutdown(f->client_cq);
+ drain_cq(f->client_cq);
+ grpc_completion_queue_destroy(f->client_cq);
+}
+
+static void simple_request_body(grpc_end2end_test_fixture f) {
+ grpc_call *c;
+ grpc_call *s;
+ gpr_timespec deadline = five_seconds_time();
+ cq_verifier *v_client = cq_verifier_create(f.client_cq);
+ cq_verifier *v_server = cq_verifier_create(f.server_cq);
+
+ c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
+ deadline);
+ GPR_ASSERT(c);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(4)));
+ cq_expect_finish_accepted(v_client, tag(4), GRPC_OP_OK);
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
+ cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com",
+ deadline, NULL);
+ cq_verify(v_server);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_server_accept_old(s, f.server_cq, tag(102)));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s, 0));
+ cq_expect_client_metadata_read(v_client, tag(2), NULL);
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_status_old(
+ s, GRPC_STATUS_UNIMPLEMENTED, "xyz", tag(5)));
+ cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_UNIMPLEMENTED,
+ "xyz", NULL);
+ cq_verify(v_client);
+
+ cq_expect_finish_accepted(v_server, tag(5), GRPC_OP_OK);
+ cq_expect_finished(v_server, tag(102), NULL);
+ cq_verify(v_server);
+
+ grpc_call_destroy(c);
+ grpc_call_destroy(s);
+
+ cq_verifier_destroy(v_client);
+ cq_verifier_destroy(v_server);
+}
+
+static void test_max_concurrent_streams(grpc_end2end_test_config config) {
+ grpc_end2end_test_fixture f;
+ grpc_arg server_arg;
+ grpc_channel_args server_args;
+ grpc_call *c1;
+ grpc_call *c2;
+ grpc_call *s1;
+ grpc_call *s2;
+ int live_call;
+ gpr_timespec deadline;
+ cq_verifier *v_client;
+ cq_verifier *v_server;
+ grpc_event *ev;
+
+ server_arg.key = GRPC_ARG_MAX_CONCURRENT_STREAMS;
+ server_arg.type = GRPC_ARG_INTEGER;
+ server_arg.value.integer = 1;
+
+ server_args.num_args = 1;
+ server_args.args = &server_arg;
+
+ f = begin_test(config, __FUNCTION__, NULL, &server_args);
+ v_client = cq_verifier_create(f.client_cq);
+ v_server = cq_verifier_create(f.server_cq);
+
+ /* perform a ping-pong to ensure that settings have had a chance to round
+ trip */
+ simple_request_body(f);
+ /* perform another one to make sure that the one stream case still works */
+ simple_request_body(f);
+
+ /* start two requests - ensuring that the second is not accepted until
+ the first completes */
+ deadline = five_seconds_time();
+ c1 = grpc_channel_create_call_old(f.client, "/alpha", "test.google.com",
+ deadline);
+ GPR_ASSERT(c1);
+ c2 = grpc_channel_create_call_old(f.client, "/beta", "test.google.com",
+ deadline);
+ GPR_ASSERT(c1);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_invoke_old(c1, f.client_cq, tag(301), tag(302), 0));
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_invoke_old(c2, f.client_cq, tag(401), tag(402), 0));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c1, tag(303)));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c2, tag(303)));
+
+ ev = grpc_completion_queue_next(
+ f.client_cq, gpr_time_add(gpr_now(), gpr_time_from_seconds(10)));
+ GPR_ASSERT(ev);
+ GPR_ASSERT(ev->type == GRPC_FINISH_ACCEPTED);
+ GPR_ASSERT(ev->data.invoke_accepted == GRPC_OP_OK);
+ /* The /alpha or /beta calls started above could be invoked (but NOT both);
+ * check this here */
+ /* We'll get tag 303 or 403, we want 300, 400 */
+ live_call = ((int)(gpr_intptr) ev->tag) - 3;
+ grpc_event_finish(ev);
+
+ cq_expect_server_rpc_new(v_server, &s1, tag(100),
+ live_call == 300 ? "/alpha" : "/beta",
+ "test.google.com", deadline, NULL);
+ cq_verify(v_server);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_server_accept_old(s1, f.server_cq, tag(102)));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s1, 0));
+ cq_expect_client_metadata_read(v_client, tag(live_call + 1), NULL);
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_start_write_status_old(s1, GRPC_STATUS_UNIMPLEMENTED,
+ "xyz", tag(103)));
+ cq_expect_finish_accepted(v_server, tag(103), GRPC_OP_OK);
+ cq_expect_finished(v_server, tag(102), NULL);
+ cq_verify(v_server);
+
+ /* first request is finished, we should be able to start the second */
+ cq_expect_finished_with_status(v_client, tag(live_call + 2),
+ GRPC_STATUS_UNIMPLEMENTED, "xyz", NULL);
+ cq_expect_finish_accepted(v_client, tag(live_call + 3), GRPC_OP_OK);
+ live_call = (live_call == 300) ? 400 : 300;
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(200)));
+ cq_expect_server_rpc_new(v_server, &s2, tag(200),
+ live_call == 300 ? "/alpha" : "/beta",
+ "test.google.com", deadline, NULL);
+ cq_verify(v_server);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_server_accept_old(s2, f.server_cq, tag(202)));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s2, 0));
+ cq_expect_client_metadata_read(v_client, tag(live_call + 1), NULL);
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_start_write_status_old(s2, GRPC_STATUS_UNIMPLEMENTED,
+ "xyz", tag(203)));
+ cq_expect_finish_accepted(v_server, tag(203), GRPC_OP_OK);
+ cq_expect_finished(v_server, tag(202), NULL);
+ cq_verify(v_server);
+
+ cq_expect_finished_with_status(v_client, tag(live_call + 2),
+ GRPC_STATUS_UNIMPLEMENTED, "xyz", NULL);
+ cq_verify(v_client);
+
+ cq_verifier_destroy(v_client);
+ cq_verifier_destroy(v_server);
+
+ grpc_call_destroy(c1);
+ grpc_call_destroy(s1);
+ grpc_call_destroy(c2);
+ grpc_call_destroy(s2);
+
+ end_test(&f);
+ config.tear_down_data(&f);
+}
+
+void grpc_end2end_tests(grpc_end2end_test_config config) {
+ test_max_concurrent_streams(config);
+}
diff --git a/test/core/end2end/tests/no_op_legacy.c b/test/core/end2end/tests/no_op_legacy.c
new file mode 100644
index 0000000000..bd4ff06701
--- /dev/null
+++ b/test/core/end2end/tests/no_op_legacy.c
@@ -0,0 +1,109 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <grpc/byte_buffer.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "test/core/end2end/cq_verifier.h"
+
+enum { TIMEOUT = 200000 };
+
+static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
+ const char *test_name,
+ grpc_channel_args *client_args,
+ grpc_channel_args *server_args) {
+ grpc_end2end_test_fixture f;
+ gpr_log(GPR_INFO, "%s/%s", test_name, config.name);
+ f = config.create_fixture(client_args, server_args);
+ config.init_client(&f, client_args);
+ config.init_server(&f, server_args);
+ return f;
+}
+
+static gpr_timespec n_seconds_time(int n) {
+ return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
+}
+
+static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
+
+static void drain_cq(grpc_completion_queue *cq) {
+ grpc_event *ev;
+ grpc_completion_type type;
+ do {
+ ev = grpc_completion_queue_next(cq, five_seconds_time());
+ GPR_ASSERT(ev);
+ type = ev->type;
+ grpc_event_finish(ev);
+ } while (type != GRPC_QUEUE_SHUTDOWN);
+}
+
+static void shutdown_server(grpc_end2end_test_fixture *f) {
+ if (!f->server) return;
+ grpc_server_shutdown(f->server);
+ grpc_server_destroy(f->server);
+ f->server = NULL;
+}
+
+static void shutdown_client(grpc_end2end_test_fixture *f) {
+ if (!f->client) return;
+ grpc_channel_destroy(f->client);
+ f->client = NULL;
+}
+
+static void end_test(grpc_end2end_test_fixture *f) {
+ shutdown_server(f);
+ shutdown_client(f);
+
+ grpc_completion_queue_shutdown(f->server_cq);
+ drain_cq(f->server_cq);
+ grpc_completion_queue_destroy(f->server_cq);
+ grpc_completion_queue_shutdown(f->client_cq);
+ drain_cq(f->client_cq);
+ grpc_completion_queue_destroy(f->client_cq);
+}
+
+static void test_no_op(grpc_end2end_test_config config) {
+ grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
+ end_test(&f);
+ config.tear_down_data(&f);
+}
+
+void grpc_end2end_tests(grpc_end2end_test_config config) { test_no_op(config); }
diff --git a/test/core/end2end/tests/ping_pong_streaming_legacy.c b/test/core/end2end/tests/ping_pong_streaming_legacy.c
new file mode 100644
index 0000000000..0c034a1996
--- /dev/null
+++ b/test/core/end2end/tests/ping_pong_streaming_legacy.c
@@ -0,0 +1,203 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <grpc/byte_buffer.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "test/core/end2end/cq_verifier.h"
+
+enum { TIMEOUT = 200000 };
+
+static void *tag(gpr_intptr t) { return (void *)t; }
+
+static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
+ const char *test_name,
+ grpc_channel_args *client_args,
+ grpc_channel_args *server_args) {
+ grpc_end2end_test_fixture f;
+ gpr_log(GPR_INFO, "%s/%s", test_name, config.name);
+ f = config.create_fixture(client_args, server_args);
+ config.init_client(&f, client_args);
+ config.init_server(&f, server_args);
+ return f;
+}
+
+static gpr_timespec n_seconds_time(int n) {
+ return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
+}
+
+static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
+
+static void drain_cq(grpc_completion_queue *cq) {
+ grpc_event *ev;
+ grpc_completion_type type;
+ do {
+ ev = grpc_completion_queue_next(cq, five_seconds_time());
+ GPR_ASSERT(ev);
+ type = ev->type;
+ grpc_event_finish(ev);
+ } while (type != GRPC_QUEUE_SHUTDOWN);
+}
+
+static void shutdown_server(grpc_end2end_test_fixture *f) {
+ if (!f->server) return;
+ grpc_server_shutdown(f->server);
+ grpc_server_destroy(f->server);
+ f->server = NULL;
+}
+
+static void shutdown_client(grpc_end2end_test_fixture *f) {
+ if (!f->client) return;
+ grpc_channel_destroy(f->client);
+ f->client = NULL;
+}
+
+static void end_test(grpc_end2end_test_fixture *f) {
+ shutdown_server(f);
+ shutdown_client(f);
+
+ grpc_completion_queue_shutdown(f->server_cq);
+ drain_cq(f->server_cq);
+ grpc_completion_queue_destroy(f->server_cq);
+ grpc_completion_queue_shutdown(f->client_cq);
+ drain_cq(f->client_cq);
+ grpc_completion_queue_destroy(f->client_cq);
+}
+
+/* Client pings and server pongs. Repeat messages rounds before finishing. */
+static void test_pingpong_streaming(grpc_end2end_test_config config,
+ int messages) {
+ int i;
+ grpc_call *c;
+ grpc_call *s = NULL;
+ gpr_slice request_payload_slice = gpr_slice_from_copied_string("hello world");
+ gpr_slice response_payload_slice = gpr_slice_from_copied_string("hello you");
+ grpc_byte_buffer *request_payload = NULL;
+ grpc_byte_buffer *response_payload = NULL;
+ gpr_timespec deadline = n_seconds_time(messages * 5);
+ grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
+ cq_verifier *v_client = cq_verifier_create(f.client_cq);
+ cq_verifier *v_server = cq_verifier_create(f.server_cq);
+
+ gpr_log(GPR_INFO, "testing with %d message pairs.", messages);
+ c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
+ deadline);
+ GPR_ASSERT(c);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
+
+ cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com",
+ deadline, NULL);
+ cq_verify(v_server);
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_server_accept_old(s, f.server_cq, tag(102)));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s, 0));
+
+ cq_expect_client_metadata_read(v_client, tag(2), NULL);
+ cq_verify(v_client);
+
+ for (i = 0; i < messages; i++) {
+ request_payload = grpc_byte_buffer_create(&request_payload_slice, 1);
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_start_write_old(c, request_payload, tag(2), 0));
+ /* destroy byte buffer early to ensure async code keeps track of its
+ contents
+ correctly */
+ grpc_byte_buffer_destroy(request_payload);
+ cq_expect_write_accepted(v_client, tag(2), GRPC_OP_OK);
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(s, tag(3)));
+ cq_expect_read(v_server, tag(3),
+ gpr_slice_from_copied_string("hello world"));
+ cq_verify(v_server);
+
+ response_payload = grpc_byte_buffer_create(&response_payload_slice, 1);
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_start_write_old(s, response_payload, tag(4), 0));
+ /* destroy byte buffer early to ensure async code keeps track of its
+ contents
+ correctly */
+ grpc_byte_buffer_destroy(response_payload);
+ cq_expect_write_accepted(v_server, tag(4), GRPC_OP_OK);
+ cq_verify(v_server);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(c, tag(5)));
+ cq_expect_read(v_client, tag(5), gpr_slice_from_copied_string("hello you"));
+ cq_verify(v_client);
+ }
+
+ gpr_slice_unref(request_payload_slice);
+ gpr_slice_unref(response_payload_slice);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(6)));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_status_old(
+ s, GRPC_STATUS_UNIMPLEMENTED, "xyz", tag(7)));
+
+ cq_expect_finish_accepted(v_client, tag(6), GRPC_OP_OK);
+ cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_UNIMPLEMENTED,
+ "xyz", NULL);
+ cq_verify(v_client);
+
+ cq_expect_finish_accepted(v_server, tag(7), GRPC_OP_OK);
+ cq_expect_finished(v_server, tag(102), NULL);
+ cq_verify(v_server);
+
+ grpc_call_destroy(c);
+ grpc_call_destroy(s);
+
+ end_test(&f);
+ config.tear_down_data(&f);
+
+ cq_verifier_destroy(v_client);
+ cq_verifier_destroy(v_server);
+}
+
+void grpc_end2end_tests(grpc_end2end_test_config config) {
+ int i;
+
+ for (i = 1; i < 10; i++) {
+ test_pingpong_streaming(config, i);
+ }
+}
diff --git a/test/core/end2end/tests/request_response_with_binary_metadata_and_payload.c b/test/core/end2end/tests/request_response_with_binary_metadata_and_payload.c
index daadcf619b..ec66d781e9 100644
--- a/test/core/end2end/tests/request_response_with_binary_metadata_and_payload.c
+++ b/test/core/end2end/tests/request_response_with_binary_metadata_and_payload.c
@@ -114,107 +114,137 @@ static void test_request_response_with_metadata_and_payload(
grpc_byte_buffer *response_payload =
grpc_byte_buffer_create(&response_payload_slice, 1);
gpr_timespec deadline = five_seconds_time();
- /* staggered lengths to ensure we hit various branches in base64 encode/decode
- */
- grpc_metadata meta1 = {
- "key1-bin", "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc", 13};
- grpc_metadata meta2 = {
- "key2-bin", "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d",
- 14};
- grpc_metadata meta3 = {
- "key3-bin",
- "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee", 15};
- grpc_metadata meta4 = {
- "key4-bin",
- "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff", 16};
+ grpc_metadata meta_c[2] = {
+ {"key1-bin", "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc", 13},
+ {"key2-bin", "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d",
+ 14}};
+ grpc_metadata meta_s[2] = {
+ {"key3-bin",
+ "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee", 15},
+ {"key4-bin",
+ "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff", 16}};
grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
cq_verifier *v_client = cq_verifier_create(f.client_cq);
cq_verifier *v_server = cq_verifier_create(f.server_cq);
-
- GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
-
- /* byte buffer holds the slice, we can unref it already */
- gpr_slice_unref(request_payload_slice);
- gpr_slice_unref(response_payload_slice);
-
- c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
- deadline);
+ grpc_op ops[6];
+ grpc_op *op;
+ grpc_metadata_array initial_metadata_recv;
+ grpc_metadata_array trailing_metadata_recv;
+ grpc_metadata_array request_metadata_recv;
+ grpc_byte_buffer *request_payload_recv = NULL;
+ grpc_byte_buffer *response_payload_recv = NULL;
+ grpc_call_details call_details;
+ grpc_status_code status;
+ char *details = NULL;
+ size_t details_capacity = 0;
+ int was_cancelled = 2;
+
+ c = grpc_channel_create_call(f.client, f.client_cq, "/foo", "test.google.com",
+ deadline);
GPR_ASSERT(c);
- /* add multiple metadata */
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(c, &meta1, 0));
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(c, &meta2, 0));
-
- GPR_ASSERT(GRPC_CALL_OK ==
- grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
-
- GPR_ASSERT(GRPC_CALL_OK ==
- grpc_call_start_write_old(c, request_payload, tag(4), 0));
- /* destroy byte buffer early to ensure async code keeps track of its contents
- correctly */
- grpc_byte_buffer_destroy(request_payload);
- cq_expect_write_accepted(v_client, tag(4), GRPC_OP_OK);
- cq_verify(v_client);
-
- cq_expect_server_rpc_new(
- v_server, &s, tag(100), "/foo", "test.google.com", deadline, "key1-bin",
- "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc", "key2-bin",
- "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d", NULL);
+ grpc_metadata_array_init(&initial_metadata_recv);
+ grpc_metadata_array_init(&trailing_metadata_recv);
+ grpc_metadata_array_init(&request_metadata_recv);
+ grpc_call_details_init(&call_details);
+
+ op = ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 2;
+ op->data.send_initial_metadata.metadata = meta_c;
+ op++;
+ op->op = GRPC_OP_SEND_MESSAGE;
+ op->data.send_message = request_payload;
+ op++;
+ op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
+ op++;
+ op->op = GRPC_OP_RECV_INITIAL_METADATA;
+ op->data.recv_initial_metadata = &initial_metadata_recv;
+ op++;
+ op->op = GRPC_OP_RECV_MESSAGE;
+ op->data.recv_message = &response_payload_recv;
+ op++;
+ op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
+ op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
+ op->data.recv_status_on_client.status = &status;
+ op->data.recv_status_on_client.status_details = &details;
+ op->data.recv_status_on_client.status_details_capacity = &details_capacity;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(c, ops, op - ops, tag(1)));
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(f.server, &s,
+ &call_details,
+ &request_metadata_recv,
+ f.server_cq, tag(101)));
+ cq_expect_completion(v_server, tag(101), GRPC_OP_OK);
cq_verify(v_server);
- grpc_call_server_accept_old(s, f.server_cq, tag(102));
-
- /* add multiple metadata */
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(s, &meta3, 0));
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(s, &meta4, 0));
-
- grpc_call_server_end_initial_metadata_old(s, 0);
-
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(s, tag(5)));
- cq_expect_read(v_server, tag(5), gpr_slice_from_copied_string("hello world"));
+ op = ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 2;
+ op->data.send_initial_metadata.metadata = meta_s;
+ op++;
+ op->op = GRPC_OP_SEND_MESSAGE;
+ op->data.send_message = response_payload;
+ op++;
+ op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
+ op->data.send_status_from_server.trailing_metadata_count = 0;
+ op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED;
+ op->data.send_status_from_server.status_details = "xyz";
+ op++;
+ op->op = GRPC_OP_RECV_MESSAGE;
+ op->data.recv_message = &request_payload_recv;
+ op++;
+ op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
+ op->data.recv_close_on_server.cancelled = &was_cancelled;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(s, ops, op - ops, tag(102)));
+
+ cq_expect_completion(v_server, tag(102), GRPC_OP_OK);
cq_verify(v_server);
- GPR_ASSERT(GRPC_CALL_OK ==
- grpc_call_start_write_old(s, response_payload, tag(6), 0));
- /* destroy byte buffer early to ensure async code keeps track of its contents
- correctly */
- grpc_byte_buffer_destroy(response_payload);
- cq_expect_write_accepted(v_server, tag(6), GRPC_OP_OK);
- cq_verify(v_server);
-
- /* fetch metadata.. */
- cq_expect_client_metadata_read(
- v_client, tag(2), "key3-bin",
- "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee",
- "key4-bin",
- "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff", NULL);
+ cq_expect_completion(v_client, tag(1), GRPC_OP_OK);
cq_verify(v_client);
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(c, tag(7)));
- cq_expect_read(v_client, tag(7), gpr_slice_from_copied_string("hello you"));
- cq_verify(v_client);
-
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(8)));
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_status_old(
- s, GRPC_STATUS_UNIMPLEMENTED, "xyz", tag(9)));
-
- cq_expect_finish_accepted(v_client, tag(8), GRPC_OP_OK);
- cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_UNIMPLEMENTED,
- "xyz", NULL);
- cq_verify(v_client);
-
- cq_expect_finish_accepted(v_server, tag(9), GRPC_OP_OK);
- cq_expect_finished(v_server, tag(102), NULL);
- cq_verify(v_server);
+ GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
+ GPR_ASSERT(0 == strcmp(details, "xyz"));
+ GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
+ GPR_ASSERT(0 == strcmp(call_details.host, "test.google.com"));
+ GPR_ASSERT(was_cancelled == 1);
+ GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, "hello world"));
+ GPR_ASSERT(byte_buffer_eq_string(response_payload_recv, "hello you"));
+ GPR_ASSERT(contains_metadata(
+ &request_metadata_recv, "key1-bin",
+ "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc"));
+ GPR_ASSERT(contains_metadata(
+ &request_metadata_recv, "key2-bin",
+ "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d"));
+ GPR_ASSERT(contains_metadata(
+ &initial_metadata_recv, "key3-bin",
+ "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee"));
+ GPR_ASSERT(contains_metadata(
+ &initial_metadata_recv, "key4-bin",
+ "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"));
+
+ gpr_free(details);
+ grpc_metadata_array_destroy(&initial_metadata_recv);
+ grpc_metadata_array_destroy(&trailing_metadata_recv);
+ grpc_metadata_array_destroy(&request_metadata_recv);
+ grpc_call_details_destroy(&call_details);
grpc_call_destroy(c);
grpc_call_destroy(s);
- end_test(&f);
- config.tear_down_data(&f);
-
cq_verifier_destroy(v_client);
cq_verifier_destroy(v_server);
+
+ grpc_byte_buffer_destroy(request_payload);
+ grpc_byte_buffer_destroy(response_payload);
+ grpc_byte_buffer_destroy(request_payload_recv);
+ grpc_byte_buffer_destroy(response_payload_recv);
+
+ end_test(&f);
+ config.tear_down_data(&f);
}
void grpc_end2end_tests(grpc_end2end_test_config config) {
diff --git a/test/core/end2end/tests/request_response_with_binary_metadata_and_payload_legacy.c b/test/core/end2end/tests/request_response_with_binary_metadata_and_payload_legacy.c
new file mode 100644
index 0000000000..daadcf619b
--- /dev/null
+++ b/test/core/end2end/tests/request_response_with_binary_metadata_and_payload_legacy.c
@@ -0,0 +1,222 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <grpc/byte_buffer.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "test/core/end2end/cq_verifier.h"
+
+enum { TIMEOUT = 200000 };
+
+static void *tag(gpr_intptr t) { return (void *)t; }
+
+static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
+ const char *test_name,
+ grpc_channel_args *client_args,
+ grpc_channel_args *server_args) {
+ grpc_end2end_test_fixture f;
+ gpr_log(GPR_INFO, "%s/%s", test_name, config.name);
+ f = config.create_fixture(client_args, server_args);
+ config.init_client(&f, client_args);
+ config.init_server(&f, server_args);
+ return f;
+}
+
+static gpr_timespec n_seconds_time(int n) {
+ return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
+}
+
+static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
+
+static void drain_cq(grpc_completion_queue *cq) {
+ grpc_event *ev;
+ grpc_completion_type type;
+ do {
+ ev = grpc_completion_queue_next(cq, five_seconds_time());
+ GPR_ASSERT(ev);
+ type = ev->type;
+ grpc_event_finish(ev);
+ } while (type != GRPC_QUEUE_SHUTDOWN);
+}
+
+static void shutdown_server(grpc_end2end_test_fixture *f) {
+ if (!f->server) return;
+ grpc_server_shutdown(f->server);
+ grpc_server_destroy(f->server);
+ f->server = NULL;
+}
+
+static void shutdown_client(grpc_end2end_test_fixture *f) {
+ if (!f->client) return;
+ grpc_channel_destroy(f->client);
+ f->client = NULL;
+}
+
+static void end_test(grpc_end2end_test_fixture *f) {
+ shutdown_server(f);
+ shutdown_client(f);
+
+ grpc_completion_queue_shutdown(f->server_cq);
+ drain_cq(f->server_cq);
+ grpc_completion_queue_destroy(f->server_cq);
+ grpc_completion_queue_shutdown(f->client_cq);
+ drain_cq(f->client_cq);
+ grpc_completion_queue_destroy(f->client_cq);
+}
+
+/* Request/response with metadata and payload.*/
+static void test_request_response_with_metadata_and_payload(
+ grpc_end2end_test_config config) {
+ grpc_call *c;
+ grpc_call *s;
+ gpr_slice request_payload_slice = gpr_slice_from_copied_string("hello world");
+ gpr_slice response_payload_slice = gpr_slice_from_copied_string("hello you");
+ grpc_byte_buffer *request_payload =
+ grpc_byte_buffer_create(&request_payload_slice, 1);
+ grpc_byte_buffer *response_payload =
+ grpc_byte_buffer_create(&response_payload_slice, 1);
+ gpr_timespec deadline = five_seconds_time();
+ /* staggered lengths to ensure we hit various branches in base64 encode/decode
+ */
+ grpc_metadata meta1 = {
+ "key1-bin", "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc", 13};
+ grpc_metadata meta2 = {
+ "key2-bin", "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d",
+ 14};
+ grpc_metadata meta3 = {
+ "key3-bin",
+ "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee", 15};
+ grpc_metadata meta4 = {
+ "key4-bin",
+ "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff", 16};
+ grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
+ cq_verifier *v_client = cq_verifier_create(f.client_cq);
+ cq_verifier *v_server = cq_verifier_create(f.server_cq);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
+
+ /* byte buffer holds the slice, we can unref it already */
+ gpr_slice_unref(request_payload_slice);
+ gpr_slice_unref(response_payload_slice);
+
+ c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
+ deadline);
+ GPR_ASSERT(c);
+
+ /* add multiple metadata */
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(c, &meta1, 0));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(c, &meta2, 0));
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_start_write_old(c, request_payload, tag(4), 0));
+ /* destroy byte buffer early to ensure async code keeps track of its contents
+ correctly */
+ grpc_byte_buffer_destroy(request_payload);
+ cq_expect_write_accepted(v_client, tag(4), GRPC_OP_OK);
+ cq_verify(v_client);
+
+ cq_expect_server_rpc_new(
+ v_server, &s, tag(100), "/foo", "test.google.com", deadline, "key1-bin",
+ "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc", "key2-bin",
+ "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d", NULL);
+ cq_verify(v_server);
+
+ grpc_call_server_accept_old(s, f.server_cq, tag(102));
+
+ /* add multiple metadata */
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(s, &meta3, 0));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(s, &meta4, 0));
+
+ grpc_call_server_end_initial_metadata_old(s, 0);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(s, tag(5)));
+ cq_expect_read(v_server, tag(5), gpr_slice_from_copied_string("hello world"));
+ cq_verify(v_server);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_start_write_old(s, response_payload, tag(6), 0));
+ /* destroy byte buffer early to ensure async code keeps track of its contents
+ correctly */
+ grpc_byte_buffer_destroy(response_payload);
+ cq_expect_write_accepted(v_server, tag(6), GRPC_OP_OK);
+ cq_verify(v_server);
+
+ /* fetch metadata.. */
+ cq_expect_client_metadata_read(
+ v_client, tag(2), "key3-bin",
+ "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee",
+ "key4-bin",
+ "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff", NULL);
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(c, tag(7)));
+ cq_expect_read(v_client, tag(7), gpr_slice_from_copied_string("hello you"));
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(8)));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_status_old(
+ s, GRPC_STATUS_UNIMPLEMENTED, "xyz", tag(9)));
+
+ cq_expect_finish_accepted(v_client, tag(8), GRPC_OP_OK);
+ cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_UNIMPLEMENTED,
+ "xyz", NULL);
+ cq_verify(v_client);
+
+ cq_expect_finish_accepted(v_server, tag(9), GRPC_OP_OK);
+ cq_expect_finished(v_server, tag(102), NULL);
+ cq_verify(v_server);
+
+ grpc_call_destroy(c);
+ grpc_call_destroy(s);
+
+ end_test(&f);
+ config.tear_down_data(&f);
+
+ cq_verifier_destroy(v_client);
+ cq_verifier_destroy(v_server);
+}
+
+void grpc_end2end_tests(grpc_end2end_test_config config) {
+ test_request_response_with_metadata_and_payload(config);
+}
diff --git a/test/core/end2end/tests/request_response_with_metadata_and_payload.c b/test/core/end2end/tests/request_response_with_metadata_and_payload.c
index 0a58398c4a..1c8ba87553 100644
--- a/test/core/end2end/tests/request_response_with_metadata_and_payload.c
+++ b/test/core/end2end/tests/request_response_with_metadata_and_payload.c
@@ -114,93 +114,122 @@ static void test_request_response_with_metadata_and_payload(
grpc_byte_buffer *response_payload =
grpc_byte_buffer_create(&response_payload_slice, 1);
gpr_timespec deadline = five_seconds_time();
- grpc_metadata meta1 = {"key1", "val1", 4};
- grpc_metadata meta2 = {"key2", "val2", 4};
- grpc_metadata meta3 = {"key3", "val3", 4};
- grpc_metadata meta4 = {"key4", "val4", 4};
+ grpc_metadata meta_c[2] = {{"key1", "val1", 4}, {"key2", "val2", 4}};
+ grpc_metadata meta_s[2] = {{"key3", "val3", 4}, {"key4", "val4", 4}};
grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
cq_verifier *v_client = cq_verifier_create(f.client_cq);
cq_verifier *v_server = cq_verifier_create(f.server_cq);
-
- GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
-
- /* byte buffer holds the slice, we can unref it already */
- gpr_slice_unref(request_payload_slice);
- gpr_slice_unref(response_payload_slice);
-
- c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
- deadline);
+ grpc_op ops[6];
+ grpc_op *op;
+ grpc_metadata_array initial_metadata_recv;
+ grpc_metadata_array trailing_metadata_recv;
+ grpc_metadata_array request_metadata_recv;
+ grpc_byte_buffer *request_payload_recv = NULL;
+ grpc_byte_buffer *response_payload_recv = NULL;
+ grpc_call_details call_details;
+ grpc_status_code status;
+ char *details = NULL;
+ size_t details_capacity = 0;
+ int was_cancelled = 2;
+
+ c = grpc_channel_create_call(f.client, f.client_cq, "/foo", "test.google.com",
+ deadline);
GPR_ASSERT(c);
- /* add multiple metadata */
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(c, &meta1, 0));
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(c, &meta2, 0));
-
- GPR_ASSERT(GRPC_CALL_OK ==
- grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
-
- GPR_ASSERT(GRPC_CALL_OK ==
- grpc_call_start_write_old(c, request_payload, tag(4), 0));
- /* destroy byte buffer early to ensure async code keeps track of its contents
- correctly */
- grpc_byte_buffer_destroy(request_payload);
- cq_expect_write_accepted(v_client, tag(4), GRPC_OP_OK);
- cq_verify(v_client);
-
- cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com",
- deadline, "key1", "val1", "key2", "val2", NULL);
+ grpc_metadata_array_init(&initial_metadata_recv);
+ grpc_metadata_array_init(&trailing_metadata_recv);
+ grpc_metadata_array_init(&request_metadata_recv);
+ grpc_call_details_init(&call_details);
+
+ op = ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 2;
+ op->data.send_initial_metadata.metadata = meta_c;
+ op++;
+ op->op = GRPC_OP_SEND_MESSAGE;
+ op->data.send_message = request_payload;
+ op++;
+ op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
+ op++;
+ op->op = GRPC_OP_RECV_INITIAL_METADATA;
+ op->data.recv_initial_metadata = &initial_metadata_recv;
+ op++;
+ op->op = GRPC_OP_RECV_MESSAGE;
+ op->data.recv_message = &response_payload_recv;
+ op++;
+ op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
+ op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
+ op->data.recv_status_on_client.status = &status;
+ op->data.recv_status_on_client.status_details = &details;
+ op->data.recv_status_on_client.status_details_capacity = &details_capacity;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(c, ops, op - ops, tag(1)));
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(f.server, &s,
+ &call_details,
+ &request_metadata_recv,
+ f.server_cq, tag(101)));
+ cq_expect_completion(v_server, tag(101), GRPC_OP_OK);
cq_verify(v_server);
- grpc_call_server_accept_old(s, f.server_cq, tag(102));
-
- /* add multiple metadata */
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(s, &meta3, 0));
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(s, &meta4, 0));
-
- grpc_call_server_end_initial_metadata_old(s, 0);
-
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(s, tag(5)));
- cq_expect_read(v_server, tag(5), gpr_slice_from_copied_string("hello world"));
+ op = ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 2;
+ op->data.send_initial_metadata.metadata = meta_s;
+ op++;
+ op->op = GRPC_OP_SEND_MESSAGE;
+ op->data.send_message = response_payload;
+ op++;
+ op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
+ op->data.send_status_from_server.trailing_metadata_count = 0;
+ op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED;
+ op->data.send_status_from_server.status_details = "xyz";
+ op++;
+ op->op = GRPC_OP_RECV_MESSAGE;
+ op->data.recv_message = &request_payload_recv;
+ op++;
+ op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
+ op->data.recv_close_on_server.cancelled = &was_cancelled;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(s, ops, op - ops, tag(102)));
+
+ cq_expect_completion(v_server, tag(102), GRPC_OP_OK);
cq_verify(v_server);
- GPR_ASSERT(GRPC_CALL_OK ==
- grpc_call_start_write_old(s, response_payload, tag(6), 0));
- /* destroy byte buffer early to ensure async code keeps track of its contents
- correctly */
- grpc_byte_buffer_destroy(response_payload);
- cq_expect_write_accepted(v_server, tag(6), GRPC_OP_OK);
- cq_verify(v_server);
-
- /* fetch metadata.. */
- cq_expect_client_metadata_read(v_client, tag(2), "key3", "val3", "key4",
- "val4", NULL);
+ cq_expect_completion(v_client, tag(1), GRPC_OP_OK);
cq_verify(v_client);
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(c, tag(7)));
- cq_expect_read(v_client, tag(7), gpr_slice_from_copied_string("hello you"));
- cq_verify(v_client);
-
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(8)));
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_status_old(
- s, GRPC_STATUS_UNIMPLEMENTED, "xyz", tag(9)));
-
- cq_expect_finish_accepted(v_client, tag(8), GRPC_OP_OK);
- cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_UNIMPLEMENTED,
- "xyz", NULL);
- cq_verify(v_client);
-
- cq_expect_finish_accepted(v_server, tag(9), GRPC_OP_OK);
- cq_expect_finished(v_server, tag(102), NULL);
- cq_verify(v_server);
+ GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
+ GPR_ASSERT(0 == strcmp(details, "xyz"));
+ GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
+ GPR_ASSERT(0 == strcmp(call_details.host, "test.google.com"));
+ GPR_ASSERT(was_cancelled == 1);
+ GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, "hello world"));
+ GPR_ASSERT(byte_buffer_eq_string(response_payload_recv, "hello you"));
+ GPR_ASSERT(contains_metadata(&request_metadata_recv, "key1", "val1"));
+ GPR_ASSERT(contains_metadata(&request_metadata_recv, "key2", "val2"));
+ GPR_ASSERT(contains_metadata(&initial_metadata_recv, "key3", "val3"));
+ GPR_ASSERT(contains_metadata(&initial_metadata_recv, "key4", "val4"));
+
+ gpr_free(details);
+ grpc_metadata_array_destroy(&initial_metadata_recv);
+ grpc_metadata_array_destroy(&trailing_metadata_recv);
+ grpc_metadata_array_destroy(&request_metadata_recv);
+ grpc_call_details_destroy(&call_details);
grpc_call_destroy(c);
grpc_call_destroy(s);
- end_test(&f);
- config.tear_down_data(&f);
-
cq_verifier_destroy(v_client);
cq_verifier_destroy(v_server);
+
+ grpc_byte_buffer_destroy(request_payload);
+ grpc_byte_buffer_destroy(response_payload);
+ grpc_byte_buffer_destroy(request_payload_recv);
+ grpc_byte_buffer_destroy(response_payload_recv);
+
+ end_test(&f);
+ config.tear_down_data(&f);
}
void grpc_end2end_tests(grpc_end2end_test_config config) {
diff --git a/test/core/end2end/tests/request_response_with_metadata_and_payload_legacy.c b/test/core/end2end/tests/request_response_with_metadata_and_payload_legacy.c
new file mode 100644
index 0000000000..0a58398c4a
--- /dev/null
+++ b/test/core/end2end/tests/request_response_with_metadata_and_payload_legacy.c
@@ -0,0 +1,208 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <grpc/byte_buffer.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "test/core/end2end/cq_verifier.h"
+
+enum { TIMEOUT = 200000 };
+
+static void *tag(gpr_intptr t) { return (void *)t; }
+
+static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
+ const char *test_name,
+ grpc_channel_args *client_args,
+ grpc_channel_args *server_args) {
+ grpc_end2end_test_fixture f;
+ gpr_log(GPR_INFO, "%s/%s", test_name, config.name);
+ f = config.create_fixture(client_args, server_args);
+ config.init_client(&f, client_args);
+ config.init_server(&f, server_args);
+ return f;
+}
+
+static gpr_timespec n_seconds_time(int n) {
+ return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
+}
+
+static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
+
+static void drain_cq(grpc_completion_queue *cq) {
+ grpc_event *ev;
+ grpc_completion_type type;
+ do {
+ ev = grpc_completion_queue_next(cq, five_seconds_time());
+ GPR_ASSERT(ev);
+ type = ev->type;
+ grpc_event_finish(ev);
+ } while (type != GRPC_QUEUE_SHUTDOWN);
+}
+
+static void shutdown_server(grpc_end2end_test_fixture *f) {
+ if (!f->server) return;
+ grpc_server_shutdown(f->server);
+ grpc_server_destroy(f->server);
+ f->server = NULL;
+}
+
+static void shutdown_client(grpc_end2end_test_fixture *f) {
+ if (!f->client) return;
+ grpc_channel_destroy(f->client);
+ f->client = NULL;
+}
+
+static void end_test(grpc_end2end_test_fixture *f) {
+ shutdown_server(f);
+ shutdown_client(f);
+
+ grpc_completion_queue_shutdown(f->server_cq);
+ drain_cq(f->server_cq);
+ grpc_completion_queue_destroy(f->server_cq);
+ grpc_completion_queue_shutdown(f->client_cq);
+ drain_cq(f->client_cq);
+ grpc_completion_queue_destroy(f->client_cq);
+}
+
+/* Request/response with metadata and payload.*/
+static void test_request_response_with_metadata_and_payload(
+ grpc_end2end_test_config config) {
+ grpc_call *c;
+ grpc_call *s;
+ gpr_slice request_payload_slice = gpr_slice_from_copied_string("hello world");
+ gpr_slice response_payload_slice = gpr_slice_from_copied_string("hello you");
+ grpc_byte_buffer *request_payload =
+ grpc_byte_buffer_create(&request_payload_slice, 1);
+ grpc_byte_buffer *response_payload =
+ grpc_byte_buffer_create(&response_payload_slice, 1);
+ gpr_timespec deadline = five_seconds_time();
+ grpc_metadata meta1 = {"key1", "val1", 4};
+ grpc_metadata meta2 = {"key2", "val2", 4};
+ grpc_metadata meta3 = {"key3", "val3", 4};
+ grpc_metadata meta4 = {"key4", "val4", 4};
+ grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
+ cq_verifier *v_client = cq_verifier_create(f.client_cq);
+ cq_verifier *v_server = cq_verifier_create(f.server_cq);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
+
+ /* byte buffer holds the slice, we can unref it already */
+ gpr_slice_unref(request_payload_slice);
+ gpr_slice_unref(response_payload_slice);
+
+ c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
+ deadline);
+ GPR_ASSERT(c);
+
+ /* add multiple metadata */
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(c, &meta1, 0));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(c, &meta2, 0));
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_start_write_old(c, request_payload, tag(4), 0));
+ /* destroy byte buffer early to ensure async code keeps track of its contents
+ correctly */
+ grpc_byte_buffer_destroy(request_payload);
+ cq_expect_write_accepted(v_client, tag(4), GRPC_OP_OK);
+ cq_verify(v_client);
+
+ cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com",
+ deadline, "key1", "val1", "key2", "val2", NULL);
+ cq_verify(v_server);
+
+ grpc_call_server_accept_old(s, f.server_cq, tag(102));
+
+ /* add multiple metadata */
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(s, &meta3, 0));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(s, &meta4, 0));
+
+ grpc_call_server_end_initial_metadata_old(s, 0);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(s, tag(5)));
+ cq_expect_read(v_server, tag(5), gpr_slice_from_copied_string("hello world"));
+ cq_verify(v_server);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_start_write_old(s, response_payload, tag(6), 0));
+ /* destroy byte buffer early to ensure async code keeps track of its contents
+ correctly */
+ grpc_byte_buffer_destroy(response_payload);
+ cq_expect_write_accepted(v_server, tag(6), GRPC_OP_OK);
+ cq_verify(v_server);
+
+ /* fetch metadata.. */
+ cq_expect_client_metadata_read(v_client, tag(2), "key3", "val3", "key4",
+ "val4", NULL);
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(c, tag(7)));
+ cq_expect_read(v_client, tag(7), gpr_slice_from_copied_string("hello you"));
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(8)));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_status_old(
+ s, GRPC_STATUS_UNIMPLEMENTED, "xyz", tag(9)));
+
+ cq_expect_finish_accepted(v_client, tag(8), GRPC_OP_OK);
+ cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_UNIMPLEMENTED,
+ "xyz", NULL);
+ cq_verify(v_client);
+
+ cq_expect_finish_accepted(v_server, tag(9), GRPC_OP_OK);
+ cq_expect_finished(v_server, tag(102), NULL);
+ cq_verify(v_server);
+
+ grpc_call_destroy(c);
+ grpc_call_destroy(s);
+
+ end_test(&f);
+ config.tear_down_data(&f);
+
+ cq_verifier_destroy(v_client);
+ cq_verifier_destroy(v_server);
+}
+
+void grpc_end2end_tests(grpc_end2end_test_config config) {
+ test_request_response_with_metadata_and_payload(config);
+}
diff --git a/test/core/end2end/tests/request_response_with_payload.c b/test/core/end2end/tests/request_response_with_payload.c
index d3b237bc34..30e96def3e 100644
--- a/test/core/end2end/tests/request_response_with_payload.c
+++ b/test/core/end2end/tests/request_response_with_payload.c
@@ -103,10 +103,10 @@ static void end_test(grpc_end2end_test_fixture *f) {
}
static void request_response_with_payload(grpc_end2end_test_fixture f) {
- grpc_call *c;
- grpc_call *s;
gpr_slice request_payload_slice = gpr_slice_from_copied_string("hello world");
gpr_slice response_payload_slice = gpr_slice_from_copied_string("hello you");
+ grpc_call *c;
+ grpc_call *s;
grpc_byte_buffer *request_payload =
grpc_byte_buffer_create(&request_payload_slice, 1);
grpc_byte_buffer *response_payload =
@@ -114,71 +114,108 @@ static void request_response_with_payload(grpc_end2end_test_fixture f) {
gpr_timespec deadline = five_seconds_time();
cq_verifier *v_client = cq_verifier_create(f.client_cq);
cq_verifier *v_server = cq_verifier_create(f.server_cq);
-
- /* byte buffer holds the slice, we can unref it already */
- gpr_slice_unref(request_payload_slice);
- gpr_slice_unref(response_payload_slice);
-
- GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
-
- c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
- deadline);
+ grpc_op ops[6];
+ grpc_op *op;
+ grpc_metadata_array initial_metadata_recv;
+ grpc_metadata_array trailing_metadata_recv;
+ grpc_metadata_array request_metadata_recv;
+ grpc_byte_buffer *request_payload_recv = NULL;
+ grpc_byte_buffer *response_payload_recv = NULL;
+ grpc_call_details call_details;
+ grpc_status_code status;
+ char *details = NULL;
+ size_t details_capacity = 0;
+ int was_cancelled = 2;
+
+ c = grpc_channel_create_call(f.client, f.client_cq, "/foo", "test.google.com",
+ deadline);
GPR_ASSERT(c);
- GPR_ASSERT(GRPC_CALL_OK ==
- grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
-
- GPR_ASSERT(GRPC_CALL_OK ==
- grpc_call_start_write_old(c, request_payload, tag(4), 0));
- /* destroy byte buffer early to ensure async code keeps track of its contents
- correctly */
- grpc_byte_buffer_destroy(request_payload);
- cq_expect_write_accepted(v_client, tag(4), GRPC_OP_OK);
- cq_verify(v_client);
-
- cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com",
- deadline, NULL);
+ grpc_metadata_array_init(&initial_metadata_recv);
+ grpc_metadata_array_init(&trailing_metadata_recv);
+ grpc_metadata_array_init(&request_metadata_recv);
+ grpc_call_details_init(&call_details);
+
+ op = ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 0;
+ op++;
+ op->op = GRPC_OP_SEND_MESSAGE;
+ op->data.send_message = request_payload;
+ op++;
+ op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
+ op++;
+ op->op = GRPC_OP_RECV_INITIAL_METADATA;
+ op->data.recv_initial_metadata = &initial_metadata_recv;
+ op++;
+ op->op = GRPC_OP_RECV_MESSAGE;
+ op->data.recv_message = &response_payload_recv;
+ op++;
+ op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
+ op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
+ op->data.recv_status_on_client.status = &status;
+ op->data.recv_status_on_client.status_details = &details;
+ op->data.recv_status_on_client.status_details_capacity = &details_capacity;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(c, ops, op - ops, tag(1)));
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(f.server, &s,
+ &call_details,
+ &request_metadata_recv,
+ f.server_cq, tag(101)));
+ cq_expect_completion(v_server, tag(101), GRPC_OP_OK);
cq_verify(v_server);
- GPR_ASSERT(GRPC_CALL_OK ==
- grpc_call_server_accept_old(s, f.server_cq, tag(102)));
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s, 0));
- cq_expect_client_metadata_read(v_client, tag(2), NULL);
- cq_verify(v_client);
-
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(s, tag(5)));
- cq_expect_read(v_server, tag(5), gpr_slice_from_copied_string("hello world"));
- cq_verify(v_server);
-
- GPR_ASSERT(GRPC_CALL_OK ==
- grpc_call_start_write_old(s, response_payload, tag(6), 0));
- /* destroy byte buffer early to ensure async code keeps track of its contents
- correctly */
- grpc_byte_buffer_destroy(response_payload);
- cq_expect_write_accepted(v_server, tag(6), GRPC_OP_OK);
+ op = ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 0;
+ op++;
+ op->op = GRPC_OP_SEND_MESSAGE;
+ op->data.send_message = response_payload;
+ op++;
+ op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
+ op->data.send_status_from_server.trailing_metadata_count = 0;
+ op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED;
+ op->data.send_status_from_server.status_details = "xyz";
+ op++;
+ op->op = GRPC_OP_RECV_MESSAGE;
+ op->data.recv_message = &request_payload_recv;
+ op++;
+ op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
+ op->data.recv_close_on_server.cancelled = &was_cancelled;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(s, ops, op - ops, tag(102)));
+
+ cq_expect_completion(v_server, tag(102), GRPC_OP_OK);
cq_verify(v_server);
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(c, tag(7)));
- cq_expect_read(v_client, tag(7), gpr_slice_from_copied_string("hello you"));
-
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(8)));
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_status_old(
- s, GRPC_STATUS_UNIMPLEMENTED, "xyz", tag(9)));
-
- cq_expect_finish_accepted(v_client, tag(8), GRPC_OP_OK);
- cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_UNIMPLEMENTED,
- "xyz", NULL);
+ cq_expect_completion(v_client, tag(1), GRPC_OP_OK);
cq_verify(v_client);
- cq_expect_finish_accepted(v_server, tag(9), GRPC_OP_OK);
- cq_expect_finished(v_server, tag(102), NULL);
- cq_verify(v_server);
+ GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
+ GPR_ASSERT(0 == strcmp(details, "xyz"));
+ GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
+ GPR_ASSERT(0 == strcmp(call_details.host, "test.google.com"));
+ GPR_ASSERT(was_cancelled == 1);
+ GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, "hello world"));
+ GPR_ASSERT(byte_buffer_eq_string(response_payload_recv, "hello you"));
+
+ gpr_free(details);
+ grpc_metadata_array_destroy(&initial_metadata_recv);
+ grpc_metadata_array_destroy(&trailing_metadata_recv);
+ grpc_metadata_array_destroy(&request_metadata_recv);
+ grpc_call_details_destroy(&call_details);
grpc_call_destroy(c);
grpc_call_destroy(s);
cq_verifier_destroy(v_client);
cq_verifier_destroy(v_server);
+
+ grpc_byte_buffer_destroy(request_payload);
+ grpc_byte_buffer_destroy(response_payload);
+ grpc_byte_buffer_destroy(request_payload_recv);
+ grpc_byte_buffer_destroy(response_payload_recv);
}
/* Client sends a request with payload, server reads then returns a response
diff --git a/test/core/end2end/tests/request_response_with_payload_legacy.c b/test/core/end2end/tests/request_response_with_payload_legacy.c
new file mode 100644
index 0000000000..d3b237bc34
--- /dev/null
+++ b/test/core/end2end/tests/request_response_with_payload_legacy.c
@@ -0,0 +1,208 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <grpc/byte_buffer.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "test/core/end2end/cq_verifier.h"
+
+enum { TIMEOUT = 200000 };
+
+static void *tag(gpr_intptr t) { return (void *)t; }
+
+static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
+ const char *test_name,
+ grpc_channel_args *client_args,
+ grpc_channel_args *server_args) {
+ grpc_end2end_test_fixture f;
+ gpr_log(GPR_INFO, "%s/%s", test_name, config.name);
+ f = config.create_fixture(client_args, server_args);
+ config.init_client(&f, client_args);
+ config.init_server(&f, server_args);
+ return f;
+}
+
+static gpr_timespec n_seconds_time(int n) {
+ return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
+}
+
+static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
+
+static void drain_cq(grpc_completion_queue *cq) {
+ grpc_event *ev;
+ grpc_completion_type type;
+ do {
+ ev = grpc_completion_queue_next(cq, five_seconds_time());
+ GPR_ASSERT(ev);
+ type = ev->type;
+ grpc_event_finish(ev);
+ } while (type != GRPC_QUEUE_SHUTDOWN);
+}
+
+static void shutdown_server(grpc_end2end_test_fixture *f) {
+ if (!f->server) return;
+ grpc_server_shutdown(f->server);
+ grpc_server_destroy(f->server);
+ f->server = NULL;
+}
+
+static void shutdown_client(grpc_end2end_test_fixture *f) {
+ if (!f->client) return;
+ grpc_channel_destroy(f->client);
+ f->client = NULL;
+}
+
+static void end_test(grpc_end2end_test_fixture *f) {
+ shutdown_server(f);
+ shutdown_client(f);
+
+ grpc_completion_queue_shutdown(f->server_cq);
+ drain_cq(f->server_cq);
+ grpc_completion_queue_destroy(f->server_cq);
+ grpc_completion_queue_shutdown(f->client_cq);
+ drain_cq(f->client_cq);
+ grpc_completion_queue_destroy(f->client_cq);
+}
+
+static void request_response_with_payload(grpc_end2end_test_fixture f) {
+ grpc_call *c;
+ grpc_call *s;
+ gpr_slice request_payload_slice = gpr_slice_from_copied_string("hello world");
+ gpr_slice response_payload_slice = gpr_slice_from_copied_string("hello you");
+ grpc_byte_buffer *request_payload =
+ grpc_byte_buffer_create(&request_payload_slice, 1);
+ grpc_byte_buffer *response_payload =
+ grpc_byte_buffer_create(&response_payload_slice, 1);
+ gpr_timespec deadline = five_seconds_time();
+ cq_verifier *v_client = cq_verifier_create(f.client_cq);
+ cq_verifier *v_server = cq_verifier_create(f.server_cq);
+
+ /* byte buffer holds the slice, we can unref it already */
+ gpr_slice_unref(request_payload_slice);
+ gpr_slice_unref(response_payload_slice);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
+
+ c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
+ deadline);
+ GPR_ASSERT(c);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_start_write_old(c, request_payload, tag(4), 0));
+ /* destroy byte buffer early to ensure async code keeps track of its contents
+ correctly */
+ grpc_byte_buffer_destroy(request_payload);
+ cq_expect_write_accepted(v_client, tag(4), GRPC_OP_OK);
+ cq_verify(v_client);
+
+ cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com",
+ deadline, NULL);
+ cq_verify(v_server);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_server_accept_old(s, f.server_cq, tag(102)));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s, 0));
+ cq_expect_client_metadata_read(v_client, tag(2), NULL);
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(s, tag(5)));
+ cq_expect_read(v_server, tag(5), gpr_slice_from_copied_string("hello world"));
+ cq_verify(v_server);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_start_write_old(s, response_payload, tag(6), 0));
+ /* destroy byte buffer early to ensure async code keeps track of its contents
+ correctly */
+ grpc_byte_buffer_destroy(response_payload);
+ cq_expect_write_accepted(v_server, tag(6), GRPC_OP_OK);
+ cq_verify(v_server);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(c, tag(7)));
+ cq_expect_read(v_client, tag(7), gpr_slice_from_copied_string("hello you"));
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(8)));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_status_old(
+ s, GRPC_STATUS_UNIMPLEMENTED, "xyz", tag(9)));
+
+ cq_expect_finish_accepted(v_client, tag(8), GRPC_OP_OK);
+ cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_UNIMPLEMENTED,
+ "xyz", NULL);
+ cq_verify(v_client);
+
+ cq_expect_finish_accepted(v_server, tag(9), GRPC_OP_OK);
+ cq_expect_finished(v_server, tag(102), NULL);
+ cq_verify(v_server);
+
+ grpc_call_destroy(c);
+ grpc_call_destroy(s);
+
+ cq_verifier_destroy(v_client);
+ cq_verifier_destroy(v_server);
+}
+
+/* Client sends a request with payload, server reads then returns a response
+ payload and status. */
+static void test_invoke_request_response_with_payload(
+ grpc_end2end_test_config config) {
+ grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
+ request_response_with_payload(f);
+ end_test(&f);
+ config.tear_down_data(&f);
+}
+
+static void test_invoke_10_request_response_with_payload(
+ grpc_end2end_test_config config) {
+ int i;
+ grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
+ for (i = 0; i < 10; i++) {
+ request_response_with_payload(f);
+ }
+ end_test(&f);
+ config.tear_down_data(&f);
+}
+
+void grpc_end2end_tests(grpc_end2end_test_config config) {
+ test_invoke_request_response_with_payload(config);
+ test_invoke_10_request_response_with_payload(config);
+}
diff --git a/test/core/end2end/tests/request_response_with_trailing_metadata_and_payload.c b/test/core/end2end/tests/request_response_with_trailing_metadata_and_payload.c
index f5f0e646ea..5878058c98 100644
--- a/test/core/end2end/tests/request_response_with_trailing_metadata_and_payload.c
+++ b/test/core/end2end/tests/request_response_with_trailing_metadata_and_payload.c
@@ -114,98 +114,126 @@ static void test_request_response_with_metadata_and_payload(
grpc_byte_buffer *response_payload =
grpc_byte_buffer_create(&response_payload_slice, 1);
gpr_timespec deadline = five_seconds_time();
- grpc_metadata meta1 = {"key1", "val1", 4};
- grpc_metadata meta2 = {"key2", "val2", 4};
- grpc_metadata meta3 = {"key3", "val3", 4};
- grpc_metadata meta4 = {"key4", "val4", 4};
- grpc_metadata meta5 = {"key5", "val5", 4};
- grpc_metadata meta6 = {"key6", "val6", 4};
+ grpc_metadata meta_c[2] = {{"key1", "val1", 4}, {"key2", "val2", 4}};
+ grpc_metadata meta_s[2] = {{"key3", "val3", 4}, {"key4", "val4", 4}};
+ grpc_metadata meta_t[2] = {{"key5", "val5", 4}, {"key6", "val6", 4}};
grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
cq_verifier *v_client = cq_verifier_create(f.client_cq);
cq_verifier *v_server = cq_verifier_create(f.server_cq);
-
- GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
-
- /* byte buffer holds the slice, we can unref it already */
- gpr_slice_unref(request_payload_slice);
- gpr_slice_unref(response_payload_slice);
-
- c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
- deadline);
+ grpc_op ops[6];
+ grpc_op *op;
+ grpc_metadata_array initial_metadata_recv;
+ grpc_metadata_array trailing_metadata_recv;
+ grpc_metadata_array request_metadata_recv;
+ grpc_byte_buffer *request_payload_recv = NULL;
+ grpc_byte_buffer *response_payload_recv = NULL;
+ grpc_call_details call_details;
+ grpc_status_code status;
+ char *details = NULL;
+ size_t details_capacity = 0;
+ int was_cancelled = 2;
+
+ c = grpc_channel_create_call(f.client, f.client_cq, "/foo", "test.google.com",
+ deadline);
GPR_ASSERT(c);
- /* add multiple metadata */
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(c, &meta1, 0));
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(c, &meta2, 0));
-
- GPR_ASSERT(GRPC_CALL_OK ==
- grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
-
- GPR_ASSERT(GRPC_CALL_OK ==
- grpc_call_start_write_old(c, request_payload, tag(4), 0));
- /* destroy byte buffer early to ensure async code keeps track of its contents
- correctly */
- grpc_byte_buffer_destroy(request_payload);
- cq_expect_write_accepted(v_client, tag(4), GRPC_OP_OK);
- cq_verify(v_client);
-
- cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com",
- deadline, "key1", "val1", "key2", "val2", NULL);
+ grpc_metadata_array_init(&initial_metadata_recv);
+ grpc_metadata_array_init(&trailing_metadata_recv);
+ grpc_metadata_array_init(&request_metadata_recv);
+ grpc_call_details_init(&call_details);
+
+ op = ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 2;
+ op->data.send_initial_metadata.metadata = meta_c;
+ op++;
+ op->op = GRPC_OP_SEND_MESSAGE;
+ op->data.send_message = request_payload;
+ op++;
+ op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
+ op++;
+ op->op = GRPC_OP_RECV_INITIAL_METADATA;
+ op->data.recv_initial_metadata = &initial_metadata_recv;
+ op++;
+ op->op = GRPC_OP_RECV_MESSAGE;
+ op->data.recv_message = &response_payload_recv;
+ op++;
+ op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
+ op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
+ op->data.recv_status_on_client.status = &status;
+ op->data.recv_status_on_client.status_details = &details;
+ op->data.recv_status_on_client.status_details_capacity = &details_capacity;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(c, ops, op - ops, tag(1)));
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(f.server, &s,
+ &call_details,
+ &request_metadata_recv,
+ f.server_cq, tag(101)));
+ cq_expect_completion(v_server, tag(101), GRPC_OP_OK);
cq_verify(v_server);
- grpc_call_server_accept_old(s, f.server_cq, tag(102));
-
- /* add multiple metadata */
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(s, &meta3, 0));
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(s, &meta4, 0));
-
- grpc_call_server_end_initial_metadata_old(s, 0);
-
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(s, &meta5, 0));
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(s, &meta6, 0));
-
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(s, tag(5)));
- cq_expect_read(v_server, tag(5), gpr_slice_from_copied_string("hello world"));
- cq_verify(v_server);
-
- GPR_ASSERT(GRPC_CALL_OK ==
- grpc_call_start_write_old(s, response_payload, tag(6), 0));
- /* destroy byte buffer early to ensure async code keeps track of its contents
- correctly */
- grpc_byte_buffer_destroy(response_payload);
- cq_expect_write_accepted(v_server, tag(6), GRPC_OP_OK);
+ op = ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 2;
+ op->data.send_initial_metadata.metadata = meta_s;
+ op++;
+ op->op = GRPC_OP_SEND_MESSAGE;
+ op->data.send_message = response_payload;
+ op++;
+ op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
+ op->data.send_status_from_server.trailing_metadata_count = 2;
+ op->data.send_status_from_server.trailing_metadata = meta_t;
+ op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED;
+ op->data.send_status_from_server.status_details = "xyz";
+ op++;
+ op->op = GRPC_OP_RECV_MESSAGE;
+ op->data.recv_message = &request_payload_recv;
+ op++;
+ op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
+ op->data.recv_close_on_server.cancelled = &was_cancelled;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(s, ops, op - ops, tag(102)));
+
+ cq_expect_completion(v_server, tag(102), GRPC_OP_OK);
cq_verify(v_server);
- /* fetch metadata.. */
- cq_expect_client_metadata_read(v_client, tag(2), "key3", "val3", "key4",
- "val4", NULL);
+ cq_expect_completion(v_client, tag(1), GRPC_OP_OK);
cq_verify(v_client);
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(c, tag(7)));
- cq_expect_read(v_client, tag(7), gpr_slice_from_copied_string("hello you"));
- cq_verify(v_client);
-
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(8)));
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_status_old(
- s, GRPC_STATUS_UNIMPLEMENTED, "xyz", tag(9)));
-
- cq_expect_finish_accepted(v_client, tag(8), GRPC_OP_OK);
- cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_UNIMPLEMENTED,
- "xyz", "key5", "val5", "key6", "val6", NULL);
- cq_verify(v_client);
-
- cq_expect_finish_accepted(v_server, tag(9), GRPC_OP_OK);
- cq_expect_finished(v_server, tag(102), NULL);
- cq_verify(v_server);
+ GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
+ GPR_ASSERT(0 == strcmp(details, "xyz"));
+ GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
+ GPR_ASSERT(0 == strcmp(call_details.host, "test.google.com"));
+ GPR_ASSERT(was_cancelled == 1);
+ GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, "hello world"));
+ GPR_ASSERT(byte_buffer_eq_string(response_payload_recv, "hello you"));
+ GPR_ASSERT(contains_metadata(&request_metadata_recv, "key1", "val1"));
+ GPR_ASSERT(contains_metadata(&request_metadata_recv, "key2", "val2"));
+ GPR_ASSERT(contains_metadata(&initial_metadata_recv, "key3", "val3"));
+ GPR_ASSERT(contains_metadata(&initial_metadata_recv, "key4", "val4"));
+ GPR_ASSERT(contains_metadata(&trailing_metadata_recv, "key5", "val5"));
+ GPR_ASSERT(contains_metadata(&trailing_metadata_recv, "key6", "val6"));
+
+ gpr_free(details);
+ grpc_metadata_array_destroy(&initial_metadata_recv);
+ grpc_metadata_array_destroy(&trailing_metadata_recv);
+ grpc_metadata_array_destroy(&request_metadata_recv);
+ grpc_call_details_destroy(&call_details);
grpc_call_destroy(c);
grpc_call_destroy(s);
- end_test(&f);
- config.tear_down_data(&f);
-
cq_verifier_destroy(v_client);
cq_verifier_destroy(v_server);
+
+ grpc_byte_buffer_destroy(request_payload);
+ grpc_byte_buffer_destroy(response_payload);
+ grpc_byte_buffer_destroy(request_payload_recv);
+ grpc_byte_buffer_destroy(response_payload_recv);
+
+ end_test(&f);
+ config.tear_down_data(&f);
}
void grpc_end2end_tests(grpc_end2end_test_config config) {
diff --git a/test/core/end2end/tests/request_response_with_trailing_metadata_and_payload_legacy.c b/test/core/end2end/tests/request_response_with_trailing_metadata_and_payload_legacy.c
new file mode 100644
index 0000000000..f5f0e646ea
--- /dev/null
+++ b/test/core/end2end/tests/request_response_with_trailing_metadata_and_payload_legacy.c
@@ -0,0 +1,213 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <grpc/byte_buffer.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "test/core/end2end/cq_verifier.h"
+
+enum { TIMEOUT = 200000 };
+
+static void *tag(gpr_intptr t) { return (void *)t; }
+
+static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
+ const char *test_name,
+ grpc_channel_args *client_args,
+ grpc_channel_args *server_args) {
+ grpc_end2end_test_fixture f;
+ gpr_log(GPR_INFO, "%s/%s", test_name, config.name);
+ f = config.create_fixture(client_args, server_args);
+ config.init_client(&f, client_args);
+ config.init_server(&f, server_args);
+ return f;
+}
+
+static gpr_timespec n_seconds_time(int n) {
+ return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
+}
+
+static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
+
+static void drain_cq(grpc_completion_queue *cq) {
+ grpc_event *ev;
+ grpc_completion_type type;
+ do {
+ ev = grpc_completion_queue_next(cq, five_seconds_time());
+ GPR_ASSERT(ev);
+ type = ev->type;
+ grpc_event_finish(ev);
+ } while (type != GRPC_QUEUE_SHUTDOWN);
+}
+
+static void shutdown_server(grpc_end2end_test_fixture *f) {
+ if (!f->server) return;
+ grpc_server_shutdown(f->server);
+ grpc_server_destroy(f->server);
+ f->server = NULL;
+}
+
+static void shutdown_client(grpc_end2end_test_fixture *f) {
+ if (!f->client) return;
+ grpc_channel_destroy(f->client);
+ f->client = NULL;
+}
+
+static void end_test(grpc_end2end_test_fixture *f) {
+ shutdown_server(f);
+ shutdown_client(f);
+
+ grpc_completion_queue_shutdown(f->server_cq);
+ drain_cq(f->server_cq);
+ grpc_completion_queue_destroy(f->server_cq);
+ grpc_completion_queue_shutdown(f->client_cq);
+ drain_cq(f->client_cq);
+ grpc_completion_queue_destroy(f->client_cq);
+}
+
+/* Request/response with metadata and payload.*/
+static void test_request_response_with_metadata_and_payload(
+ grpc_end2end_test_config config) {
+ grpc_call *c;
+ grpc_call *s;
+ gpr_slice request_payload_slice = gpr_slice_from_copied_string("hello world");
+ gpr_slice response_payload_slice = gpr_slice_from_copied_string("hello you");
+ grpc_byte_buffer *request_payload =
+ grpc_byte_buffer_create(&request_payload_slice, 1);
+ grpc_byte_buffer *response_payload =
+ grpc_byte_buffer_create(&response_payload_slice, 1);
+ gpr_timespec deadline = five_seconds_time();
+ grpc_metadata meta1 = {"key1", "val1", 4};
+ grpc_metadata meta2 = {"key2", "val2", 4};
+ grpc_metadata meta3 = {"key3", "val3", 4};
+ grpc_metadata meta4 = {"key4", "val4", 4};
+ grpc_metadata meta5 = {"key5", "val5", 4};
+ grpc_metadata meta6 = {"key6", "val6", 4};
+ grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
+ cq_verifier *v_client = cq_verifier_create(f.client_cq);
+ cq_verifier *v_server = cq_verifier_create(f.server_cq);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
+
+ /* byte buffer holds the slice, we can unref it already */
+ gpr_slice_unref(request_payload_slice);
+ gpr_slice_unref(response_payload_slice);
+
+ c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
+ deadline);
+ GPR_ASSERT(c);
+
+ /* add multiple metadata */
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(c, &meta1, 0));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(c, &meta2, 0));
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_start_write_old(c, request_payload, tag(4), 0));
+ /* destroy byte buffer early to ensure async code keeps track of its contents
+ correctly */
+ grpc_byte_buffer_destroy(request_payload);
+ cq_expect_write_accepted(v_client, tag(4), GRPC_OP_OK);
+ cq_verify(v_client);
+
+ cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com",
+ deadline, "key1", "val1", "key2", "val2", NULL);
+ cq_verify(v_server);
+
+ grpc_call_server_accept_old(s, f.server_cq, tag(102));
+
+ /* add multiple metadata */
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(s, &meta3, 0));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(s, &meta4, 0));
+
+ grpc_call_server_end_initial_metadata_old(s, 0);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(s, &meta5, 0));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(s, &meta6, 0));
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(s, tag(5)));
+ cq_expect_read(v_server, tag(5), gpr_slice_from_copied_string("hello world"));
+ cq_verify(v_server);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_start_write_old(s, response_payload, tag(6), 0));
+ /* destroy byte buffer early to ensure async code keeps track of its contents
+ correctly */
+ grpc_byte_buffer_destroy(response_payload);
+ cq_expect_write_accepted(v_server, tag(6), GRPC_OP_OK);
+ cq_verify(v_server);
+
+ /* fetch metadata.. */
+ cq_expect_client_metadata_read(v_client, tag(2), "key3", "val3", "key4",
+ "val4", NULL);
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(c, tag(7)));
+ cq_expect_read(v_client, tag(7), gpr_slice_from_copied_string("hello you"));
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(8)));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_status_old(
+ s, GRPC_STATUS_UNIMPLEMENTED, "xyz", tag(9)));
+
+ cq_expect_finish_accepted(v_client, tag(8), GRPC_OP_OK);
+ cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_UNIMPLEMENTED,
+ "xyz", "key5", "val5", "key6", "val6", NULL);
+ cq_verify(v_client);
+
+ cq_expect_finish_accepted(v_server, tag(9), GRPC_OP_OK);
+ cq_expect_finished(v_server, tag(102), NULL);
+ cq_verify(v_server);
+
+ grpc_call_destroy(c);
+ grpc_call_destroy(s);
+
+ end_test(&f);
+ config.tear_down_data(&f);
+
+ cq_verifier_destroy(v_client);
+ cq_verifier_destroy(v_server);
+}
+
+void grpc_end2end_tests(grpc_end2end_test_config config) {
+ test_request_response_with_metadata_and_payload(config);
+}
diff --git a/test/core/end2end/tests/request_with_large_metadata.c b/test/core/end2end/tests/request_with_large_metadata.c
index f6c892cbcb..076cb9435c 100644
--- a/test/core/end2end/tests/request_with_large_metadata.c
+++ b/test/core/end2end/tests/request_with_large_metadata.c
@@ -106,63 +106,120 @@ static void end_test(grpc_end2end_test_fixture *f) {
static void test_request_with_large_metadata(grpc_end2end_test_config config) {
grpc_call *c;
grpc_call *s;
+ gpr_slice request_payload_slice = gpr_slice_from_copied_string("hello world");
+ grpc_byte_buffer *request_payload =
+ grpc_byte_buffer_create(&request_payload_slice, 1);
gpr_timespec deadline = five_seconds_time();
grpc_metadata meta;
grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
cq_verifier *v_client = cq_verifier_create(f.client_cq);
cq_verifier *v_server = cq_verifier_create(f.server_cq);
+ grpc_op ops[6];
+ grpc_op *op;
+ grpc_metadata_array initial_metadata_recv;
+ grpc_metadata_array trailing_metadata_recv;
+ grpc_metadata_array request_metadata_recv;
+ grpc_byte_buffer *request_payload_recv = NULL;
+ grpc_call_details call_details;
+ grpc_status_code status;
+ char *details = NULL;
+ size_t details_capacity = 0;
+ int was_cancelled = 2;
const int large_size = 64 * 1024;
- GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
+ c = grpc_channel_create_call(f.client, f.client_cq, "/foo", "test.google.com",
+ deadline);
+ GPR_ASSERT(c);
meta.key = "key";
meta.value = gpr_malloc(large_size + 1);
- memset(meta.value, 'a', large_size);
- meta.value[large_size] = 0;
+ memset((char *)meta.value, 'a', large_size);
+ ((char*)meta.value)[large_size] = 0;
meta.value_length = large_size;
- c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
- deadline);
- GPR_ASSERT(c);
-
- /* add the metadata */
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(c, &meta, 0));
-
- GPR_ASSERT(GRPC_CALL_OK ==
- grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
-
- cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com",
- deadline, "key", meta.value, NULL);
+ grpc_metadata_array_init(&initial_metadata_recv);
+ grpc_metadata_array_init(&trailing_metadata_recv);
+ grpc_metadata_array_init(&request_metadata_recv);
+ grpc_call_details_init(&call_details);
+
+ op = ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 1;
+ op->data.send_initial_metadata.metadata = &meta;
+ op++;
+ op->op = GRPC_OP_SEND_MESSAGE;
+ op->data.send_message = request_payload;
+ op++;
+ op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
+ op++;
+ op->op = GRPC_OP_RECV_INITIAL_METADATA;
+ op->data.recv_initial_metadata = &initial_metadata_recv;
+ op++;
+ op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
+ op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
+ op->data.recv_status_on_client.status = &status;
+ op->data.recv_status_on_client.status_details = &details;
+ op->data.recv_status_on_client.status_details_capacity = &details_capacity;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(c, ops, op - ops, tag(1)));
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(f.server, &s,
+ &call_details,
+ &request_metadata_recv,
+ f.server_cq, tag(101)));
+ cq_expect_completion(v_server, tag(101), GRPC_OP_OK);
cq_verify(v_server);
- grpc_call_accept(s, f.server_cq, tag(102), 0);
+ op = ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 0;
+ op++;
+ op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
+ op->data.send_status_from_server.trailing_metadata_count = 0;
+ op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED;
+ op->data.send_status_from_server.status_details = "xyz";
+ op++;
+ op->op = GRPC_OP_RECV_MESSAGE;
+ op->data.recv_message = &request_payload_recv;
+ op++;
+ op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
+ op->data.recv_close_on_server.cancelled = &was_cancelled;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(s, ops, op - ops, tag(102)));
+
+ cq_expect_completion(v_server, tag(102), GRPC_OP_OK);
+ cq_verify(v_server);
- /* fetch metadata.. */
- cq_expect_client_metadata_read(v_client, tag(2), NULL);
+ cq_expect_completion(v_client, tag(1), GRPC_OP_OK);
cq_verify(v_client);
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(8)));
- GPR_ASSERT(GRPC_CALL_OK ==
- grpc_call_start_write_status_old(s, GRPC_STATUS_OK, NULL, tag(9)));
-
- cq_expect_finish_accepted(v_client, tag(8), GRPC_OP_OK);
- cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_OK, NULL, NULL);
- cq_verify(v_client);
+ GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
+ GPR_ASSERT(0 == strcmp(details, "xyz"));
+ GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
+ GPR_ASSERT(0 == strcmp(call_details.host, "test.google.com"));
+ GPR_ASSERT(was_cancelled == 1);
+ GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, "hello world"));
+ GPR_ASSERT(contains_metadata(&request_metadata_recv, "key", meta.value));
- cq_expect_finish_accepted(v_server, tag(9), GRPC_OP_OK);
- cq_expect_finished(v_server, tag(102), NULL);
- cq_verify(v_server);
+ gpr_free(details);
+ grpc_metadata_array_destroy(&initial_metadata_recv);
+ grpc_metadata_array_destroy(&trailing_metadata_recv);
+ grpc_metadata_array_destroy(&request_metadata_recv);
+ grpc_call_details_destroy(&call_details);
grpc_call_destroy(c);
grpc_call_destroy(s);
- end_test(&f);
- config.tear_down_data(&f);
-
cq_verifier_destroy(v_client);
cq_verifier_destroy(v_server);
- gpr_free(meta.value);
+ grpc_byte_buffer_destroy(request_payload);
+ grpc_byte_buffer_destroy(request_payload_recv);
+
+ gpr_free((char *)meta.value);
+
+ end_test(&f);
+ config.tear_down_data(&f);
}
void grpc_end2end_tests(grpc_end2end_test_config config) {
diff --git a/test/core/end2end/tests/request_with_large_metadata_legacy.c b/test/core/end2end/tests/request_with_large_metadata_legacy.c
new file mode 100644
index 0000000000..560df5c4ab
--- /dev/null
+++ b/test/core/end2end/tests/request_with_large_metadata_legacy.c
@@ -0,0 +1,172 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <grpc/byte_buffer.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "test/core/end2end/cq_verifier.h"
+
+enum { TIMEOUT = 200000 };
+
+static void *tag(gpr_intptr t) { return (void *)t; }
+
+static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
+ const char *test_name,
+ grpc_channel_args *client_args,
+ grpc_channel_args *server_args) {
+ grpc_end2end_test_fixture f;
+ gpr_log(GPR_INFO, "%s/%s", test_name, config.name);
+ f = config.create_fixture(client_args, server_args);
+ config.init_client(&f, client_args);
+ config.init_server(&f, server_args);
+ return f;
+}
+
+static gpr_timespec n_seconds_time(int n) {
+ return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
+}
+
+static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
+
+static void drain_cq(grpc_completion_queue *cq) {
+ grpc_event *ev;
+ grpc_completion_type type;
+ do {
+ ev = grpc_completion_queue_next(cq, five_seconds_time());
+ GPR_ASSERT(ev);
+ type = ev->type;
+ grpc_event_finish(ev);
+ } while (type != GRPC_QUEUE_SHUTDOWN);
+}
+
+static void shutdown_server(grpc_end2end_test_fixture *f) {
+ if (!f->server) return;
+ grpc_server_shutdown(f->server);
+ grpc_server_destroy(f->server);
+ f->server = NULL;
+}
+
+static void shutdown_client(grpc_end2end_test_fixture *f) {
+ if (!f->client) return;
+ grpc_channel_destroy(f->client);
+ f->client = NULL;
+}
+
+static void end_test(grpc_end2end_test_fixture *f) {
+ shutdown_server(f);
+ shutdown_client(f);
+
+ grpc_completion_queue_shutdown(f->server_cq);
+ drain_cq(f->server_cq);
+ grpc_completion_queue_destroy(f->server_cq);
+ grpc_completion_queue_shutdown(f->client_cq);
+ drain_cq(f->client_cq);
+ grpc_completion_queue_destroy(f->client_cq);
+}
+
+/* Request with a large amount of metadata.*/
+static void test_request_with_large_metadata(grpc_end2end_test_config config) {
+ grpc_call *c;
+ grpc_call *s;
+ gpr_timespec deadline = five_seconds_time();
+ grpc_metadata meta;
+ grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
+ cq_verifier *v_client = cq_verifier_create(f.client_cq);
+ cq_verifier *v_server = cq_verifier_create(f.server_cq);
+ const int large_size = 64 * 1024;
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
+
+ meta.key = "key";
+ meta.value = gpr_malloc(large_size + 1);
+ memset((char *)meta.value, 'a', large_size);
+ ((char*)meta.value)[large_size] = 0;
+ meta.value_length = large_size;
+
+ c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
+ deadline);
+ GPR_ASSERT(c);
+
+ /* add the metadata */
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata_old(c, &meta, 0));
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
+
+ cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com",
+ deadline, "key", meta.value, NULL);
+ cq_verify(v_server);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_server_accept_old(s, f.server_cq, tag(102)));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s, 0));
+
+ /* fetch metadata.. */
+ cq_expect_client_metadata_read(v_client, tag(2), NULL);
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(8)));
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_start_write_status_old(s, GRPC_STATUS_OK, NULL, tag(9)));
+
+ cq_expect_finish_accepted(v_client, tag(8), GRPC_OP_OK);
+ cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_OK, NULL, NULL);
+ cq_verify(v_client);
+
+ cq_expect_finish_accepted(v_server, tag(9), GRPC_OP_OK);
+ cq_expect_finished(v_server, tag(102), NULL);
+ cq_verify(v_server);
+
+ grpc_call_destroy(c);
+ grpc_call_destroy(s);
+
+ end_test(&f);
+ config.tear_down_data(&f);
+
+ cq_verifier_destroy(v_client);
+ cq_verifier_destroy(v_server);
+
+ gpr_free((char *)meta.value);
+}
+
+void grpc_end2end_tests(grpc_end2end_test_config config) {
+ test_request_with_large_metadata(config);
+}
diff --git a/test/core/end2end/tests/request_with_payload.c b/test/core/end2end/tests/request_with_payload.c
index caf5d0eb9e..dcf928cde4 100644
--- a/test/core/end2end/tests/request_with_payload.c
+++ b/test/core/end2end/tests/request_with_payload.c
@@ -106,63 +106,108 @@ static void end_test(grpc_end2end_test_fixture *f) {
static void test_invoke_request_with_payload(grpc_end2end_test_config config) {
grpc_call *c;
grpc_call *s;
- gpr_slice payload_slice = gpr_slice_from_copied_string("hello world");
- grpc_byte_buffer *payload = grpc_byte_buffer_create(&payload_slice, 1);
+ gpr_slice request_payload_slice = gpr_slice_from_copied_string("hello world");
+ grpc_byte_buffer *request_payload =
+ grpc_byte_buffer_create(&request_payload_slice, 1);
gpr_timespec deadline = five_seconds_time();
grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
cq_verifier *v_client = cq_verifier_create(f.client_cq);
cq_verifier *v_server = cq_verifier_create(f.server_cq);
-
- /* byte buffer holds the slice, we can unref it already */
- gpr_slice_unref(payload_slice);
-
- c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
- deadline);
+ grpc_op ops[6];
+ grpc_op *op;
+ grpc_metadata_array initial_metadata_recv;
+ grpc_metadata_array trailing_metadata_recv;
+ grpc_metadata_array request_metadata_recv;
+ grpc_byte_buffer *request_payload_recv = NULL;
+ grpc_call_details call_details;
+ grpc_status_code status;
+ char *details = NULL;
+ size_t details_capacity = 0;
+ int was_cancelled = 2;
+
+ c = grpc_channel_create_call(f.client, f.client_cq, "/foo", "test.google.com",
+ deadline);
GPR_ASSERT(c);
- GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
-
- GPR_ASSERT(GRPC_CALL_OK ==
- grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
-
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_old(c, payload, tag(4), 0));
- /* destroy byte buffer early to ensure async code keeps track of its contents
- correctly */
- grpc_byte_buffer_destroy(payload);
- cq_expect_write_accepted(v_client, tag(4), GRPC_OP_OK);
- cq_verify(v_client);
+ grpc_metadata_array_init(&initial_metadata_recv);
+ grpc_metadata_array_init(&trailing_metadata_recv);
+ grpc_metadata_array_init(&request_metadata_recv);
+ grpc_call_details_init(&call_details);
+
+ op = ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 0;
+ op++;
+ op->op = GRPC_OP_SEND_MESSAGE;
+ op->data.send_message = request_payload;
+ op++;
+ op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
+ op++;
+ op->op = GRPC_OP_RECV_INITIAL_METADATA;
+ op->data.recv_initial_metadata = &initial_metadata_recv;
+ op++;
+ op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
+ op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
+ op->data.recv_status_on_client.status = &status;
+ op->data.recv_status_on_client.status_details = &details;
+ op->data.recv_status_on_client.status_details_capacity = &details_capacity;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(c, ops, op - ops, tag(1)));
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(f.server, &s,
+ &call_details,
+ &request_metadata_recv,
+ f.server_cq, tag(101)));
+ cq_expect_completion(v_server, tag(101), GRPC_OP_OK);
+ cq_verify(v_server);
- cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com",
- deadline, NULL);
+ op = ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 0;
+ op++;
+ op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
+ op->data.send_status_from_server.trailing_metadata_count = 0;
+ op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED;
+ op->data.send_status_from_server.status_details = "xyz";
+ op++;
+ op->op = GRPC_OP_RECV_MESSAGE;
+ op->data.recv_message = &request_payload_recv;
+ op++;
+ op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
+ op->data.recv_close_on_server.cancelled = &was_cancelled;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(s, ops, op - ops, tag(102)));
+
+ cq_expect_completion(v_server, tag(102), GRPC_OP_OK);
cq_verify(v_server);
- grpc_call_accept(s, f.server_cq, tag(102), 0);
- cq_expect_client_metadata_read(v_client, tag(2), NULL);
+ cq_expect_completion(v_client, tag(1), GRPC_OP_OK);
cq_verify(v_client);
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(s, tag(4)));
- cq_expect_read(v_server, tag(4), gpr_slice_from_copied_string("hello world"));
-
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(5)));
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_status_old(
- s, GRPC_STATUS_UNIMPLEMENTED, "xyz", tag(6)));
- cq_expect_finish_accepted(v_client, tag(5), GRPC_OP_OK);
- cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_UNIMPLEMENTED,
- "xyz", NULL);
- cq_verify(v_client);
+ GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
+ GPR_ASSERT(0 == strcmp(details, "xyz"));
+ GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
+ GPR_ASSERT(0 == strcmp(call_details.host, "test.google.com"));
+ GPR_ASSERT(was_cancelled == 1);
+ GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, "hello world"));
- cq_expect_finish_accepted(v_server, tag(6), GRPC_OP_OK);
- cq_expect_finished(v_server, tag(102), NULL);
- cq_verify(v_server);
+ gpr_free(details);
+ grpc_metadata_array_destroy(&initial_metadata_recv);
+ grpc_metadata_array_destroy(&trailing_metadata_recv);
+ grpc_metadata_array_destroy(&request_metadata_recv);
+ grpc_call_details_destroy(&call_details);
grpc_call_destroy(c);
grpc_call_destroy(s);
- end_test(&f);
- config.tear_down_data(&f);
-
cq_verifier_destroy(v_client);
cq_verifier_destroy(v_server);
+
+ grpc_byte_buffer_destroy(request_payload);
+ grpc_byte_buffer_destroy(request_payload_recv);
+
+ end_test(&f);
+ config.tear_down_data(&f);
}
void grpc_end2end_tests(grpc_end2end_test_config config) {
diff --git a/test/core/end2end/tests/request_with_payload_legacy.c b/test/core/end2end/tests/request_with_payload_legacy.c
new file mode 100644
index 0000000000..5cda853aa9
--- /dev/null
+++ b/test/core/end2end/tests/request_with_payload_legacy.c
@@ -0,0 +1,172 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <grpc/byte_buffer.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "test/core/end2end/cq_verifier.h"
+
+enum { TIMEOUT = 200000 };
+
+static void *tag(gpr_intptr t) { return (void *)t; }
+
+static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
+ const char *test_name,
+ grpc_channel_args *client_args,
+ grpc_channel_args *server_args) {
+ grpc_end2end_test_fixture f;
+ gpr_log(GPR_INFO, "%s/%s", test_name, config.name);
+ f = config.create_fixture(client_args, server_args);
+ config.init_client(&f, client_args);
+ config.init_server(&f, server_args);
+ return f;
+}
+
+static gpr_timespec n_seconds_time(int n) {
+ return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
+}
+
+static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
+
+static void drain_cq(grpc_completion_queue *cq) {
+ grpc_event *ev;
+ grpc_completion_type type;
+ do {
+ ev = grpc_completion_queue_next(cq, five_seconds_time());
+ GPR_ASSERT(ev);
+ type = ev->type;
+ grpc_event_finish(ev);
+ } while (type != GRPC_QUEUE_SHUTDOWN);
+}
+
+static void shutdown_server(grpc_end2end_test_fixture *f) {
+ if (!f->server) return;
+ grpc_server_shutdown(f->server);
+ grpc_server_destroy(f->server);
+ f->server = NULL;
+}
+
+static void shutdown_client(grpc_end2end_test_fixture *f) {
+ if (!f->client) return;
+ grpc_channel_destroy(f->client);
+ f->client = NULL;
+}
+
+static void end_test(grpc_end2end_test_fixture *f) {
+ shutdown_server(f);
+ shutdown_client(f);
+
+ grpc_completion_queue_shutdown(f->server_cq);
+ drain_cq(f->server_cq);
+ grpc_completion_queue_destroy(f->server_cq);
+ grpc_completion_queue_shutdown(f->client_cq);
+ drain_cq(f->client_cq);
+ grpc_completion_queue_destroy(f->client_cq);
+}
+
+/* Client sends a request with payload, server reads then returns status. */
+static void test_invoke_request_with_payload(grpc_end2end_test_config config) {
+ grpc_call *c;
+ grpc_call *s;
+ gpr_slice payload_slice = gpr_slice_from_copied_string("hello world");
+ grpc_byte_buffer *payload = grpc_byte_buffer_create(&payload_slice, 1);
+ gpr_timespec deadline = five_seconds_time();
+ grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
+ cq_verifier *v_client = cq_verifier_create(f.client_cq);
+ cq_verifier *v_server = cq_verifier_create(f.server_cq);
+
+ /* byte buffer holds the slice, we can unref it already */
+ gpr_slice_unref(payload_slice);
+
+ c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
+ deadline);
+ GPR_ASSERT(c);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_old(c, payload, tag(4), 0));
+ /* destroy byte buffer early to ensure async code keeps track of its contents
+ correctly */
+ grpc_byte_buffer_destroy(payload);
+ cq_expect_write_accepted(v_client, tag(4), GRPC_OP_OK);
+ cq_verify(v_client);
+
+ cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com",
+ deadline, NULL);
+ cq_verify(v_server);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_server_accept_old(s, f.server_cq, tag(102)));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s, 0));
+ cq_expect_client_metadata_read(v_client, tag(2), NULL);
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(s, tag(4)));
+ cq_expect_read(v_server, tag(4), gpr_slice_from_copied_string("hello world"));
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(5)));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_status_old(
+ s, GRPC_STATUS_UNIMPLEMENTED, "xyz", tag(6)));
+ cq_expect_finish_accepted(v_client, tag(5), GRPC_OP_OK);
+ cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_UNIMPLEMENTED,
+ "xyz", NULL);
+ cq_verify(v_client);
+
+ cq_expect_finish_accepted(v_server, tag(6), GRPC_OP_OK);
+ cq_expect_finished(v_server, tag(102), NULL);
+ cq_verify(v_server);
+
+ grpc_call_destroy(c);
+ grpc_call_destroy(s);
+
+ end_test(&f);
+ config.tear_down_data(&f);
+
+ cq_verifier_destroy(v_client);
+ cq_verifier_destroy(v_server);
+}
+
+void grpc_end2end_tests(grpc_end2end_test_config config) {
+ test_invoke_request_with_payload(config);
+}
diff --git a/test/core/end2end/tests/simple_delayed_request.c b/test/core/end2end/tests/simple_delayed_request.c
index a982bb5e1b..23cbd064b5 100644
--- a/test/core/end2end/tests/simple_delayed_request.c
+++ b/test/core/end2end/tests/simple_delayed_request.c
@@ -100,44 +100,85 @@ static void simple_delayed_request_body(grpc_end2end_test_config config,
gpr_timespec deadline = five_seconds_time();
cq_verifier *v_client = cq_verifier_create(f->client_cq);
cq_verifier *v_server = cq_verifier_create(f->server_cq);
+ grpc_op ops[6];
+ grpc_op *op;
+ grpc_metadata_array initial_metadata_recv;
+ grpc_metadata_array trailing_metadata_recv;
+ grpc_metadata_array request_metadata_recv;
+ grpc_call_details call_details;
+ grpc_status_code status;
+ char *details = NULL;
+ size_t details_capacity = 0;
+ int was_cancelled = 2;
config.init_client(f, client_args);
- c = grpc_channel_create_call_old(f->client, "/foo", "test.google.com",
- deadline);
+ c = grpc_channel_create_call(f->client, f->client_cq, "/foo", "test.google.com",
+ deadline);
GPR_ASSERT(c);
- GPR_ASSERT(GRPC_CALL_OK ==
- grpc_call_invoke_old(c, f->client_cq, tag(2), tag(3), 0));
+ grpc_metadata_array_init(&initial_metadata_recv);
+ grpc_metadata_array_init(&trailing_metadata_recv);
+ grpc_metadata_array_init(&request_metadata_recv);
+ grpc_call_details_init(&call_details);
+
+ op = ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 0;
+ op++;
+ op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
+ op++;
+ op->op = GRPC_OP_RECV_INITIAL_METADATA;
+ op->data.recv_initial_metadata = &initial_metadata_recv;
+ op++;
+ op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
+ op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
+ op->data.recv_status_on_client.status = &status;
+ op->data.recv_status_on_client.status_details = &details;
+ op->data.recv_status_on_client.status_details_capacity = &details_capacity;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(c, ops, op - ops, tag(1)));
config.init_server(f, server_args);
- cq_verify(v_client);
-
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(4)));
- cq_expect_finish_accepted(v_client, tag(4), GRPC_OP_OK);
- cq_verify(v_client);
-
- GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f->server, tag(100)));
- cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com",
- deadline, NULL);
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(f->server, &s,
+ &call_details,
+ &request_metadata_recv,
+ f->server_cq, tag(101)));
+ cq_expect_completion(v_server, tag(101), GRPC_OP_OK);
cq_verify(v_server);
- GPR_ASSERT(GRPC_CALL_OK ==
- grpc_call_server_accept_old(s, f->server_cq, tag(102)));
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s, 0));
- cq_expect_client_metadata_read(v_client, tag(2), NULL);
- cq_verify(v_client);
+ op = ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 0;
+ op++;
+ op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
+ op->data.send_status_from_server.trailing_metadata_count = 0;
+ op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED;
+ op->data.send_status_from_server.status_details = "xyz";
+ op++;
+ op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
+ op->data.recv_close_on_server.cancelled = &was_cancelled;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(s, ops, op - ops, tag(102)));
+
+ cq_expect_completion(v_server, tag(102), GRPC_OP_OK);
+ cq_verify(v_server);
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_status_old(
- s, GRPC_STATUS_UNIMPLEMENTED, "xyz", tag(5)));
- cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_UNIMPLEMENTED,
- "xyz", NULL);
+ cq_expect_completion(v_client, tag(1), GRPC_OP_OK);
cq_verify(v_client);
- cq_expect_finish_accepted(v_server, tag(5), GRPC_OP_OK);
- cq_expect_finished(v_server, tag(102), NULL);
- cq_verify(v_server);
+ GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
+ GPR_ASSERT(0 == strcmp(details, "xyz"));
+ GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
+ GPR_ASSERT(0 == strcmp(call_details.host, "test.google.com"));
+ GPR_ASSERT(was_cancelled == 1);
+
+ gpr_free(details);
+ grpc_metadata_array_destroy(&initial_metadata_recv);
+ grpc_metadata_array_destroy(&trailing_metadata_recv);
+ grpc_metadata_array_destroy(&request_metadata_recv);
+ grpc_call_details_destroy(&call_details);
grpc_call_destroy(c);
grpc_call_destroy(s);
diff --git a/test/core/end2end/tests/simple_delayed_request_legacy.c b/test/core/end2end/tests/simple_delayed_request_legacy.c
new file mode 100644
index 0000000000..a982bb5e1b
--- /dev/null
+++ b/test/core/end2end/tests/simple_delayed_request_legacy.c
@@ -0,0 +1,175 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <grpc/byte_buffer.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "test/core/end2end/cq_verifier.h"
+
+enum { TIMEOUT = 200000 };
+
+static void *tag(gpr_intptr t) { return (void *)t; }
+
+static gpr_timespec n_seconds_time(int n) {
+ return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
+}
+
+static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
+
+static void drain_cq(grpc_completion_queue *cq) {
+ grpc_event *ev;
+ grpc_completion_type type;
+ do {
+ ev = grpc_completion_queue_next(cq, five_seconds_time());
+ GPR_ASSERT(ev);
+ type = ev->type;
+ grpc_event_finish(ev);
+ } while (type != GRPC_QUEUE_SHUTDOWN);
+}
+
+static void shutdown_server(grpc_end2end_test_fixture *f) {
+ if (!f->server) return;
+ grpc_server_shutdown(f->server);
+ grpc_server_destroy(f->server);
+ f->server = NULL;
+}
+
+static void shutdown_client(grpc_end2end_test_fixture *f) {
+ if (!f->client) return;
+ grpc_channel_destroy(f->client);
+ f->client = NULL;
+}
+
+static void end_test(grpc_end2end_test_fixture *f) {
+ shutdown_server(f);
+ shutdown_client(f);
+
+ grpc_completion_queue_shutdown(f->server_cq);
+ drain_cq(f->server_cq);
+ grpc_completion_queue_destroy(f->server_cq);
+ grpc_completion_queue_shutdown(f->client_cq);
+ drain_cq(f->client_cq);
+ grpc_completion_queue_destroy(f->client_cq);
+}
+
+static void simple_delayed_request_body(grpc_end2end_test_config config,
+ grpc_end2end_test_fixture *f,
+ grpc_channel_args *client_args,
+ grpc_channel_args *server_args,
+ long delay_us) {
+ grpc_call *c;
+ grpc_call *s;
+ gpr_timespec deadline = five_seconds_time();
+ cq_verifier *v_client = cq_verifier_create(f->client_cq);
+ cq_verifier *v_server = cq_verifier_create(f->server_cq);
+
+ config.init_client(f, client_args);
+
+ c = grpc_channel_create_call_old(f->client, "/foo", "test.google.com",
+ deadline);
+ GPR_ASSERT(c);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_invoke_old(c, f->client_cq, tag(2), tag(3), 0));
+
+ config.init_server(f, server_args);
+
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(4)));
+ cq_expect_finish_accepted(v_client, tag(4), GRPC_OP_OK);
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f->server, tag(100)));
+ cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com",
+ deadline, NULL);
+ cq_verify(v_server);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_server_accept_old(s, f->server_cq, tag(102)));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s, 0));
+ cq_expect_client_metadata_read(v_client, tag(2), NULL);
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_status_old(
+ s, GRPC_STATUS_UNIMPLEMENTED, "xyz", tag(5)));
+ cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_UNIMPLEMENTED,
+ "xyz", NULL);
+ cq_verify(v_client);
+
+ cq_expect_finish_accepted(v_server, tag(5), GRPC_OP_OK);
+ cq_expect_finished(v_server, tag(102), NULL);
+ cq_verify(v_server);
+
+ grpc_call_destroy(c);
+ grpc_call_destroy(s);
+
+ cq_verifier_destroy(v_client);
+ cq_verifier_destroy(v_server);
+}
+
+static void test_simple_delayed_request_short(grpc_end2end_test_config config) {
+ grpc_end2end_test_fixture f;
+
+ gpr_log(GPR_INFO, "%s/%s", __FUNCTION__, config.name);
+ f = config.create_fixture(NULL, NULL);
+ simple_delayed_request_body(config, &f, NULL, NULL, 100000);
+ end_test(&f);
+ config.tear_down_data(&f);
+}
+
+static void test_simple_delayed_request_long(grpc_end2end_test_config config) {
+ grpc_end2end_test_fixture f;
+
+ gpr_log(GPR_INFO, "%s/%s", __FUNCTION__, config.name);
+ f = config.create_fixture(NULL, NULL);
+ /* This timeout should be longer than a single retry */
+ simple_delayed_request_body(config, &f, NULL, NULL, 1500000);
+ end_test(&f);
+ config.tear_down_data(&f);
+}
+
+void grpc_end2end_tests(grpc_end2end_test_config config) {
+ if (config.feature_mask & FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION) {
+ test_simple_delayed_request_short(config);
+ test_simple_delayed_request_long(config);
+ }
+}
diff --git a/test/core/end2end/tests/simple_request.c b/test/core/end2end/tests/simple_request.c
index 192d1ab87d..34a3f99916 100644
--- a/test/core/end2end/tests/simple_request.c
+++ b/test/core/end2end/tests/simple_request.c
@@ -39,6 +39,7 @@
#include "src/core/support/string.h"
#include <grpc/byte_buffer.h>
+#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/time.h>
@@ -109,89 +110,81 @@ static void simple_request_body(grpc_end2end_test_fixture f) {
gpr_timespec deadline = five_seconds_time();
cq_verifier *v_client = cq_verifier_create(f.client_cq);
cq_verifier *v_server = cq_verifier_create(f.server_cq);
-
- c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
- deadline);
+ grpc_op ops[6];
+ grpc_op *op;
+ grpc_metadata_array initial_metadata_recv;
+ grpc_metadata_array trailing_metadata_recv;
+ grpc_metadata_array request_metadata_recv;
+ grpc_call_details call_details;
+ grpc_status_code status;
+ char *details = NULL;
+ size_t details_capacity = 0;
+ int was_cancelled = 2;
+
+ c = grpc_channel_create_call(f.client, f.client_cq, "/foo", "test.google.com",
+ deadline);
GPR_ASSERT(c);
- GPR_ASSERT(GRPC_CALL_OK ==
- grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
-
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(4)));
- cq_expect_finish_accepted(v_client, tag(4), GRPC_OP_OK);
- cq_verify(v_client);
-
- GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
- cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com",
- deadline, NULL);
+ grpc_metadata_array_init(&initial_metadata_recv);
+ grpc_metadata_array_init(&trailing_metadata_recv);
+ grpc_metadata_array_init(&request_metadata_recv);
+ grpc_call_details_init(&call_details);
+
+ op = ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 0;
+ op++;
+ op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
+ op++;
+ op->op = GRPC_OP_RECV_INITIAL_METADATA;
+ op->data.recv_initial_metadata = &initial_metadata_recv;
+ op++;
+ op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
+ op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
+ op->data.recv_status_on_client.status = &status;
+ op->data.recv_status_on_client.status_details = &details;
+ op->data.recv_status_on_client.status_details_capacity = &details_capacity;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(c, ops, op - ops, tag(1)));
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(f.server, &s,
+ &call_details,
+ &request_metadata_recv,
+ f.server_cq, tag(101)));
+ cq_expect_completion(v_server, tag(101), GRPC_OP_OK);
cq_verify(v_server);
- GPR_ASSERT(GRPC_CALL_OK ==
- grpc_call_server_accept_old(s, f.server_cq, tag(102)));
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s, 0));
- cq_expect_client_metadata_read(v_client, tag(2), NULL);
- cq_verify(v_client);
-
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_status_old(
- s, GRPC_STATUS_UNIMPLEMENTED, "xyz", tag(5)));
- cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_UNIMPLEMENTED,
- "xyz", NULL);
- cq_verify(v_client);
-
- cq_expect_finish_accepted(v_server, tag(5), GRPC_OP_OK);
- cq_verify(v_server);
- cq_expect_finished(v_server, tag(102), NULL);
+ op = ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 0;
+ op++;
+ op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
+ op->data.send_status_from_server.trailing_metadata_count = 0;
+ op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED;
+ op->data.send_status_from_server.status_details = "xyz";
+ op++;
+ op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
+ op->data.recv_close_on_server.cancelled = &was_cancelled;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(s, ops, op - ops, tag(102)));
+
+ cq_expect_completion(v_server, tag(102), GRPC_OP_OK);
cq_verify(v_server);
- grpc_call_destroy(c);
- grpc_call_destroy(s);
-
- cq_verifier_destroy(v_client);
- cq_verifier_destroy(v_server);
-}
-
-/* an alternative ordering of the simple request body */
-static void simple_request_body2(grpc_end2end_test_fixture f) {
- grpc_call *c;
- grpc_call *s;
- gpr_timespec deadline = five_seconds_time();
- cq_verifier *v_client = cq_verifier_create(f.client_cq);
- cq_verifier *v_server = cq_verifier_create(f.server_cq);
-
- c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
- deadline);
- GPR_ASSERT(c);
-
- GPR_ASSERT(GRPC_CALL_OK ==
- grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
-
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(4)));
- cq_expect_finish_accepted(v_client, tag(4), GRPC_OP_OK);
+ cq_expect_completion(v_client, tag(1), GRPC_OP_OK);
cq_verify(v_client);
- GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
- cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com",
- deadline, NULL);
- cq_verify(v_server);
+ GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
+ GPR_ASSERT(0 == strcmp(details, "xyz"));
+ GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
+ GPR_ASSERT(0 == strcmp(call_details.host, "test.google.com"));
+ GPR_ASSERT(was_cancelled == 1);
- GPR_ASSERT(GRPC_CALL_OK ==
- grpc_call_server_accept_old(s, f.server_cq, tag(102)));
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s, 0));
-
- GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_status_old(
- s, GRPC_STATUS_UNIMPLEMENTED, "xyz", tag(5)));
- cq_expect_finish_accepted(v_server, tag(5), GRPC_OP_OK);
- cq_verify(v_server);
-
- cq_expect_client_metadata_read(v_client, tag(2), NULL);
- cq_verify(v_client);
-
- cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_UNIMPLEMENTED,
- "xyz", NULL);
- cq_verify(v_client);
-
- cq_expect_finished(v_server, tag(102), NULL);
- cq_verify(v_server);
+ gpr_free(details);
+ grpc_metadata_array_destroy(&initial_metadata_recv);
+ grpc_metadata_array_destroy(&trailing_metadata_recv);
+ grpc_metadata_array_destroy(&request_metadata_recv);
+ grpc_call_details_destroy(&call_details);
grpc_call_destroy(c);
grpc_call_destroy(s);
@@ -200,19 +193,13 @@ static void simple_request_body2(grpc_end2end_test_fixture f) {
cq_verifier_destroy(v_server);
}
-static void test_invoke_simple_request(
- grpc_end2end_test_config config, const char *name,
- void (*body)(grpc_end2end_test_fixture f)) {
- char *fullname;
+static void test_invoke_simple_request(grpc_end2end_test_config config) {
grpc_end2end_test_fixture f;
- gpr_asprintf(&fullname, "%s/%s", __FUNCTION__, name);
-
- f = begin_test(config, fullname, NULL, NULL);
- body(f);
+ f = begin_test(config, __FUNCTION__, NULL, NULL);
+ simple_request_body(f);
end_test(&f);
config.tear_down_data(&f);
- gpr_free(fullname);
}
static void test_invoke_10_simple_requests(grpc_end2end_test_config config) {
@@ -227,9 +214,6 @@ static void test_invoke_10_simple_requests(grpc_end2end_test_config config) {
}
void grpc_end2end_tests(grpc_end2end_test_config config) {
- test_invoke_simple_request(config, "simple_request_body",
- simple_request_body);
- test_invoke_simple_request(config, "simple_request_body2",
- simple_request_body2);
+ test_invoke_simple_request(config);
test_invoke_10_simple_requests(config);
}
diff --git a/test/core/end2end/tests/simple_request_legacy.c b/test/core/end2end/tests/simple_request_legacy.c
new file mode 100644
index 0000000000..db0d6d8160
--- /dev/null
+++ b/test/core/end2end/tests/simple_request_legacy.c
@@ -0,0 +1,232 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "src/core/support/string.h"
+#include <grpc/byte_buffer.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "test/core/end2end/cq_verifier.h"
+
+enum { TIMEOUT = 200000 };
+
+static void *tag(gpr_intptr t) { return (void *)t; }
+
+static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
+ const char *test_name,
+ grpc_channel_args *client_args,
+ grpc_channel_args *server_args) {
+ grpc_end2end_test_fixture f;
+ gpr_log(GPR_INFO, "%s/%s", test_name, config.name);
+ f = config.create_fixture(client_args, server_args);
+ config.init_client(&f, client_args);
+ config.init_server(&f, server_args);
+ return f;
+}
+
+static gpr_timespec n_seconds_time(int n) {
+ return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
+}
+
+static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
+
+static void drain_cq(grpc_completion_queue *cq) {
+ grpc_event *ev;
+ grpc_completion_type type;
+ do {
+ ev = grpc_completion_queue_next(cq, five_seconds_time());
+ GPR_ASSERT(ev);
+ type = ev->type;
+ grpc_event_finish(ev);
+ } while (type != GRPC_QUEUE_SHUTDOWN);
+}
+
+static void shutdown_server(grpc_end2end_test_fixture *f) {
+ if (!f->server) return;
+ grpc_server_shutdown(f->server);
+ grpc_server_destroy(f->server);
+ f->server = NULL;
+}
+
+static void shutdown_client(grpc_end2end_test_fixture *f) {
+ if (!f->client) return;
+ grpc_channel_destroy(f->client);
+ f->client = NULL;
+}
+
+static void end_test(grpc_end2end_test_fixture *f) {
+ shutdown_server(f);
+ shutdown_client(f);
+
+ grpc_completion_queue_shutdown(f->server_cq);
+ drain_cq(f->server_cq);
+ grpc_completion_queue_destroy(f->server_cq);
+ grpc_completion_queue_shutdown(f->client_cq);
+ drain_cq(f->client_cq);
+ grpc_completion_queue_destroy(f->client_cq);
+}
+
+static void simple_request_body(grpc_end2end_test_fixture f) {
+ grpc_call *c;
+ grpc_call *s;
+ gpr_timespec deadline = five_seconds_time();
+ cq_verifier *v_client = cq_verifier_create(f.client_cq);
+ cq_verifier *v_server = cq_verifier_create(f.server_cq);
+
+ c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
+ deadline);
+ GPR_ASSERT(c);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(4)));
+ cq_expect_finish_accepted(v_client, tag(4), GRPC_OP_OK);
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
+ cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com",
+ deadline, NULL);
+ cq_verify(v_server);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_server_accept_old(s, f.server_cq, tag(102)));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s, 0));
+ cq_expect_client_metadata_read(v_client, tag(2), NULL);
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_status_old(
+ s, GRPC_STATUS_UNIMPLEMENTED, "xyz", tag(5)));
+ cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_UNIMPLEMENTED,
+ "xyz", NULL);
+ cq_verify(v_client);
+
+ cq_expect_finish_accepted(v_server, tag(5), GRPC_OP_OK);
+ cq_expect_finished(v_server, tag(102), NULL);
+ cq_verify(v_server);
+
+ grpc_call_destroy(c);
+ grpc_call_destroy(s);
+
+ cq_verifier_destroy(v_client);
+ cq_verifier_destroy(v_server);
+}
+
+/* an alternative ordering of the simple request body */
+static void simple_request_body2(grpc_end2end_test_fixture f) {
+ grpc_call *c;
+ grpc_call *s;
+ gpr_timespec deadline = five_seconds_time();
+ cq_verifier *v_client = cq_verifier_create(f.client_cq);
+ cq_verifier *v_server = cq_verifier_create(f.server_cq);
+
+ c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
+ deadline);
+ GPR_ASSERT(c);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(4)));
+ cq_expect_finish_accepted(v_client, tag(4), GRPC_OP_OK);
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
+ cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com",
+ deadline, NULL);
+ cq_verify(v_server);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_server_accept_old(s, f.server_cq, tag(102)));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s, 0));
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_status_old(
+ s, GRPC_STATUS_UNIMPLEMENTED, "xyz", tag(5)));
+ cq_verify(v_server);
+
+ cq_expect_client_metadata_read(v_client, tag(2), NULL);
+ cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_UNIMPLEMENTED,
+ "xyz", NULL);
+ cq_verify(v_client);
+
+ cq_expect_finish_accepted(v_server, tag(5), GRPC_OP_OK);
+ cq_expect_finished(v_server, tag(102), NULL);
+ cq_verify(v_server);
+
+ grpc_call_destroy(c);
+ grpc_call_destroy(s);
+
+ cq_verifier_destroy(v_client);
+ cq_verifier_destroy(v_server);
+}
+
+static void test_invoke_simple_request(
+ grpc_end2end_test_config config, const char *name,
+ void (*body)(grpc_end2end_test_fixture f)) {
+ char *fullname;
+ grpc_end2end_test_fixture f;
+
+ gpr_asprintf(&fullname, "%s/%s", __FUNCTION__, name);
+
+ f = begin_test(config, fullname, NULL, NULL);
+ body(f);
+ end_test(&f);
+ config.tear_down_data(&f);
+ gpr_free(fullname);
+}
+
+static void test_invoke_10_simple_requests(grpc_end2end_test_config config) {
+ int i;
+ grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
+ for (i = 0; i < 10; i++) {
+ simple_request_body(f);
+ gpr_log(GPR_INFO, "Passed simple request %d", i);
+ }
+ end_test(&f);
+ config.tear_down_data(&f);
+}
+
+void grpc_end2end_tests(grpc_end2end_test_config config) {
+ test_invoke_simple_request(config, "simple_request_body",
+ simple_request_body);
+ test_invoke_simple_request(config, "simple_request_body2",
+ simple_request_body2);
+ test_invoke_10_simple_requests(config);
+}
diff --git a/test/core/end2end/tests/thread_stress_legacy.c b/test/core/end2end/tests/thread_stress_legacy.c
new file mode 100644
index 0000000000..e950a984ce
--- /dev/null
+++ b/test/core/end2end/tests/thread_stress_legacy.c
@@ -0,0 +1,324 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <string.h>
+
+#include "src/core/surface/event_string.h"
+#include "src/core/surface/completion_queue.h"
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/thd.h>
+
+#define SERVER_THREADS 16
+#define CLIENT_THREADS 16
+
+static grpc_end2end_test_fixture g_fixture;
+static gpr_timespec g_test_end_time;
+static gpr_event g_client_done[CLIENT_THREADS];
+static gpr_event g_server_done[SERVER_THREADS];
+static gpr_mu g_mu;
+static int g_active_requests;
+
+static gpr_timespec n_seconds_time(int n) {
+ return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
+}
+
+static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
+
+/* Drain pending events on a completion queue until it's ready to destroy.
+ Does some post-processing to safely release memory on some of the events. */
+static void drain_cq(int client, grpc_completion_queue *cq) {
+ grpc_event *ev;
+ grpc_completion_type type;
+ char *evstr;
+ int done = 0;
+ char *name = client ? "client" : "server";
+ while (!done) {
+ ev = grpc_completion_queue_next(cq, five_seconds_time());
+ if (!ev) {
+ gpr_log(GPR_ERROR, "waiting for %s cq to drain", name);
+ grpc_cq_dump_pending_ops(cq);
+ continue;
+ }
+
+ evstr = grpc_event_string(ev);
+ gpr_log(GPR_INFO, "got late %s event: %s", name, evstr);
+ gpr_free(evstr);
+
+ type = ev->type;
+ switch (type) {
+ case GRPC_SERVER_RPC_NEW:
+ gpr_free(ev->tag);
+ if (ev->call) {
+ grpc_call_destroy(ev->call);
+ }
+ break;
+ case GRPC_FINISHED:
+ grpc_call_destroy(ev->call);
+ break;
+ case GRPC_QUEUE_SHUTDOWN:
+ done = 1;
+ break;
+ case GRPC_READ:
+ case GRPC_WRITE_ACCEPTED:
+ if (!client && gpr_unref(ev->tag)) {
+ gpr_free(ev->tag);
+ }
+ default:
+ break;
+ }
+ grpc_event_finish(ev);
+ }
+}
+
+/* Kick off a new request - assumes g_mu taken */
+static void start_request(void) {
+ gpr_slice slice = gpr_slice_malloc(100);
+ grpc_byte_buffer *buf;
+ grpc_call *call = grpc_channel_create_call_old(
+ g_fixture.client, "/Foo", "test.google.com", g_test_end_time);
+
+ memset(GPR_SLICE_START_PTR(slice), 1, GPR_SLICE_LENGTH(slice));
+ buf = grpc_byte_buffer_create(&slice, 1);
+ gpr_slice_unref(slice);
+
+ g_active_requests++;
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_invoke_old(call, g_fixture.client_cq, NULL, NULL, 0));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(call, NULL));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_old(call, buf, NULL, 0));
+
+ grpc_byte_buffer_destroy(buf);
+}
+
+/* Async client: handle sending requests, reading responses, and starting
+ new requests when old ones finish */
+static void client_thread(void *p) {
+ gpr_intptr id = (gpr_intptr)p;
+ grpc_event *ev;
+ char *estr;
+
+ for (;;) {
+ ev = grpc_completion_queue_next(g_fixture.client_cq, n_seconds_time(1));
+ if (ev) {
+ switch (ev->type) {
+ default:
+ estr = grpc_event_string(ev);
+ gpr_log(GPR_ERROR, "unexpected event: %s", estr);
+ gpr_free(estr);
+ break;
+ case GRPC_READ:
+ break;
+ case GRPC_WRITE_ACCEPTED:
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(ev->call, NULL));
+ break;
+ case GRPC_FINISH_ACCEPTED:
+ break;
+ case GRPC_CLIENT_METADATA_READ:
+ break;
+ case GRPC_FINISHED:
+ /* kick off a new request if the test should still be running */
+ gpr_mu_lock(&g_mu);
+ g_active_requests--;
+ if (gpr_time_cmp(gpr_now(), g_test_end_time) < 0) {
+ start_request();
+ }
+ gpr_mu_unlock(&g_mu);
+ grpc_call_destroy(ev->call);
+ break;
+ }
+ grpc_event_finish(ev);
+ }
+ gpr_mu_lock(&g_mu);
+ if (g_active_requests == 0) {
+ gpr_mu_unlock(&g_mu);
+ break;
+ }
+ gpr_mu_unlock(&g_mu);
+ }
+
+ gpr_event_set(&g_client_done[id], (void *)1);
+}
+
+/* Request a new server call. We tag them with a ref-count that starts at two,
+ and decrements after each of: a read completes and a write completes.
+ When it drops to zero, we write status */
+static void request_server_call(void) {
+ gpr_refcount *rc = gpr_malloc(sizeof(gpr_refcount));
+ gpr_ref_init(rc, 2);
+ grpc_server_request_call_old(g_fixture.server, rc);
+}
+
+static void maybe_end_server_call(grpc_call *call, gpr_refcount *rc) {
+ if (gpr_unref(rc)) {
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_status_old(
+ call, GRPC_STATUS_OK, NULL, NULL));
+ gpr_free(rc);
+ }
+}
+
+static void server_thread(void *p) {
+ int id = (gpr_intptr)p;
+ gpr_slice slice = gpr_slice_malloc(100);
+ grpc_byte_buffer *buf;
+ grpc_event *ev;
+ char *estr;
+
+ memset(GPR_SLICE_START_PTR(slice), 1, GPR_SLICE_LENGTH(slice));
+ buf = grpc_byte_buffer_create(&slice, 1);
+ gpr_slice_unref(slice);
+
+ request_server_call();
+
+ for (;;) {
+ ev = grpc_completion_queue_next(g_fixture.server_cq, n_seconds_time(1));
+ if (ev) {
+ switch (ev->type) {
+ default:
+ estr = grpc_event_string(ev);
+ gpr_log(GPR_ERROR, "unexpected event: %s", estr);
+ gpr_free(estr);
+ break;
+ case GRPC_SERVER_RPC_NEW:
+ if (ev->call) {
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_server_accept_old(
+ ev->call, g_fixture.server_cq, ev->tag));
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_server_end_initial_metadata_old(ev->call, 0));
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_start_read_old(ev->call, ev->tag));
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_start_write_old(ev->call, buf, ev->tag, 0));
+ } else {
+ gpr_free(ev->tag);
+ }
+ break;
+ case GRPC_READ:
+ if (ev->data.read) {
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_start_read_old(ev->call, ev->tag));
+ } else {
+ maybe_end_server_call(ev->call, ev->tag);
+ }
+ break;
+ case GRPC_WRITE_ACCEPTED:
+ maybe_end_server_call(ev->call, ev->tag);
+ break;
+ case GRPC_FINISH_ACCEPTED:
+ break;
+ case GRPC_FINISHED:
+ grpc_call_destroy(ev->call);
+ request_server_call();
+ break;
+ }
+ grpc_event_finish(ev);
+ }
+ gpr_mu_lock(&g_mu);
+ if (g_active_requests == 0) {
+ gpr_mu_unlock(&g_mu);
+ break;
+ }
+ gpr_mu_unlock(&g_mu);
+ }
+
+ grpc_byte_buffer_destroy(buf);
+ gpr_event_set(&g_server_done[id], (void *)1);
+}
+
+static void run_test(grpc_end2end_test_config config, int requests_in_flight) {
+ int i;
+ gpr_thd_id thd_id;
+
+ gpr_log(GPR_INFO, "thread_stress_test/%s @ %d requests", config.name,
+ requests_in_flight);
+
+ /* setup client, server */
+ g_fixture = config.create_fixture(NULL, NULL);
+ config.init_client(&g_fixture, NULL);
+ config.init_server(&g_fixture, NULL);
+
+ /* schedule end time */
+ g_test_end_time = n_seconds_time(5);
+
+ g_active_requests = 0;
+ gpr_mu_init(&g_mu);
+
+ /* kick off threads */
+ for (i = 0; i < CLIENT_THREADS; i++) {
+ gpr_event_init(&g_client_done[i]);
+ gpr_thd_new(&thd_id, client_thread, (void *)(gpr_intptr)i, NULL);
+ }
+ for (i = 0; i < SERVER_THREADS; i++) {
+ gpr_event_init(&g_server_done[i]);
+ gpr_thd_new(&thd_id, server_thread, (void *)(gpr_intptr)i, NULL);
+ }
+
+ /* start requests */
+ gpr_mu_lock(&g_mu);
+ for (i = 0; i < requests_in_flight; i++) {
+ start_request();
+ }
+ gpr_mu_unlock(&g_mu);
+
+ /* await completion */
+ for (i = 0; i < CLIENT_THREADS; i++) {
+ gpr_event_wait(&g_client_done[i], gpr_inf_future);
+ }
+ for (i = 0; i < SERVER_THREADS; i++) {
+ gpr_event_wait(&g_server_done[i], gpr_inf_future);
+ }
+
+ /* shutdown the things */
+ grpc_server_shutdown(g_fixture.server);
+ grpc_server_destroy(g_fixture.server);
+ grpc_channel_destroy(g_fixture.client);
+
+ grpc_completion_queue_shutdown(g_fixture.server_cq);
+ drain_cq(0, g_fixture.server_cq);
+ grpc_completion_queue_destroy(g_fixture.server_cq);
+ grpc_completion_queue_shutdown(g_fixture.client_cq);
+ drain_cq(1, g_fixture.client_cq);
+ grpc_completion_queue_destroy(g_fixture.client_cq);
+
+ config.tear_down_data(&g_fixture);
+
+ gpr_mu_destroy(&g_mu);
+}
+
+void grpc_end2end_tests(grpc_end2end_test_config config) {
+ run_test(config, 1000);
+}
diff --git a/test/core/end2end/tests/writes_done_hangs_with_pending_read_legacy.c b/test/core/end2end/tests/writes_done_hangs_with_pending_read_legacy.c
new file mode 100644
index 0000000000..0c77aa2b4e
--- /dev/null
+++ b/test/core/end2end/tests/writes_done_hangs_with_pending_read_legacy.c
@@ -0,0 +1,199 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <grpc/byte_buffer.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "test/core/end2end/cq_verifier.h"
+
+enum { TIMEOUT = 200000 };
+
+static void *tag(gpr_intptr t) { return (void *)t; }
+
+static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
+ const char *test_name,
+ grpc_channel_args *client_args,
+ grpc_channel_args *server_args) {
+ grpc_end2end_test_fixture f;
+ gpr_log(GPR_INFO, "%s/%s", test_name, config.name);
+ f = config.create_fixture(client_args, server_args);
+ config.init_client(&f, client_args);
+ config.init_server(&f, server_args);
+ return f;
+}
+
+static gpr_timespec n_seconds_time(int n) {
+ return gpr_time_add(gpr_now(), gpr_time_from_micros(GPR_US_PER_SEC * n));
+}
+
+static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
+
+static void drain_cq(grpc_completion_queue *cq) {
+ grpc_event *ev;
+ grpc_completion_type type;
+ do {
+ ev = grpc_completion_queue_next(cq, five_seconds_time());
+ GPR_ASSERT(ev);
+ type = ev->type;
+ grpc_event_finish(ev);
+ } while (type != GRPC_QUEUE_SHUTDOWN);
+}
+
+static void shutdown_server(grpc_end2end_test_fixture *f) {
+ if (!f->server) return;
+ grpc_server_shutdown(f->server);
+ grpc_server_destroy(f->server);
+ f->server = NULL;
+}
+
+static void shutdown_client(grpc_end2end_test_fixture *f) {
+ if (!f->client) return;
+ grpc_channel_destroy(f->client);
+ f->client = NULL;
+}
+
+static void end_test(grpc_end2end_test_fixture *f) {
+ shutdown_server(f);
+ shutdown_client(f);
+
+ grpc_completion_queue_shutdown(f->server_cq);
+ drain_cq(f->server_cq);
+ grpc_completion_queue_destroy(f->server_cq);
+ grpc_completion_queue_shutdown(f->client_cq);
+ drain_cq(f->client_cq);
+ grpc_completion_queue_destroy(f->client_cq);
+}
+
+/* test the case when there is a pending message at the client side,
+ writes_done should not return a status without a start_read.
+ Note: this test will last for 3s. Do not run in a loop. */
+static void test_writes_done_hangs_with_pending_read(
+ grpc_end2end_test_config config) {
+ grpc_call *c;
+ grpc_call *s;
+ gpr_slice request_payload_slice = gpr_slice_from_copied_string("hello world");
+ gpr_slice response_payload_slice = gpr_slice_from_copied_string("hello you");
+ grpc_byte_buffer *request_payload =
+ grpc_byte_buffer_create(&request_payload_slice, 1);
+ grpc_byte_buffer *response_payload =
+ grpc_byte_buffer_create(&response_payload_slice, 1);
+ gpr_timespec deadline = five_seconds_time();
+ grpc_end2end_test_fixture f = begin_test(config, __FUNCTION__, NULL, NULL);
+ cq_verifier *v_client = cq_verifier_create(f.client_cq);
+ cq_verifier *v_server = cq_verifier_create(f.server_cq);
+
+ /* byte buffer holds the slice, we can unref it already */
+ gpr_slice_unref(request_payload_slice);
+ gpr_slice_unref(response_payload_slice);
+
+ c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com",
+ deadline);
+ GPR_ASSERT(c);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0));
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_start_write_old(c, request_payload, tag(4), 0));
+ /* destroy byte buffer early to ensure async code keeps track of its contents
+ correctly */
+ grpc_byte_buffer_destroy(request_payload);
+ cq_expect_write_accepted(v_client, tag(4), GRPC_OP_OK);
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100)));
+ cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com",
+ deadline, NULL);
+ cq_verify(v_server);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_server_accept_old(s, f.server_cq, tag(102)));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s, 0));
+ cq_expect_client_metadata_read(v_client, tag(2), NULL);
+ cq_verify(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(s, tag(5)));
+ cq_expect_read(v_server, tag(5), gpr_slice_from_copied_string("hello world"));
+ cq_verify(v_server);
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_start_write_old(s, response_payload, tag(6), 0));
+ /* destroy byte buffer early to ensure async code keeps track of its contents
+ correctly */
+ grpc_byte_buffer_destroy(response_payload);
+ cq_expect_write_accepted(v_server, tag(6), GRPC_OP_OK);
+ cq_verify(v_server);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(6)));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_status_old(
+ s, GRPC_STATUS_UNIMPLEMENTED, "xyz", tag(7)));
+
+ cq_expect_finish_accepted(v_client, tag(6), GRPC_OP_OK);
+ cq_verify(v_client);
+
+ /* does not return status because there is a pending message to be read */
+ cq_verify_empty(v_client);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read_old(c, tag(8)));
+ cq_expect_read(v_client, tag(8), gpr_slice_from_copied_string("hello you"));
+ cq_verify(v_client);
+
+ cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_UNIMPLEMENTED,
+ "xyz", NULL);
+ cq_verify(v_client);
+
+ cq_expect_finish_accepted(v_server, tag(7), GRPC_OP_OK);
+ cq_expect_finished(v_server, tag(102), NULL);
+ cq_verify(v_server);
+
+ grpc_call_destroy(c);
+ grpc_call_destroy(s);
+
+ end_test(&f);
+ config.tear_down_data(&f);
+
+ cq_verifier_destroy(v_client);
+ cq_verifier_destroy(v_server);
+}
+
+void grpc_end2end_tests(grpc_end2end_test_config config) {
+ test_writes_done_hangs_with_pending_read(config);
+}
diff --git a/test/core/fling/fling_stream_test.c b/test/core/fling/fling_stream_test.c
index 7f52fb1bad..1db2f1a791 100644
--- a/test/core/fling/fling_stream_test.c
+++ b/test/core/fling/fling_stream_test.c
@@ -31,7 +31,10 @@
*
*/
+#ifndef _POSIX_SOURCE
#define _POSIX_SOURCE
+#endif
+
#include <unistd.h>
#include <assert.h>
#include <stdio.h>
diff --git a/test/core/fling/fling_test.c b/test/core/fling/fling_test.c
index b2272f20c8..4f41a21aaa 100644
--- a/test/core/fling/fling_test.c
+++ b/test/core/fling/fling_test.c
@@ -31,7 +31,10 @@
*
*/
+#ifndef _POSIX_SOURCE
#define _POSIX_SOURCE
+#endif
+
#include <unistd.h>
#include <assert.h>
#include <stdio.h>
diff --git a/test/core/json/json_test.c b/test/core/json/json_test.c
index 11659a5716..6d0227ad39 100644
--- a/test/core/json/json_test.c
+++ b/test/core/json/json_test.c
@@ -151,7 +151,7 @@ static void test_pairs() {
GPR_ASSERT(!json);
}
- free(scratchpad);
+ gpr_free(scratchpad);
}
}
@@ -166,6 +166,7 @@ static void test_atypical() {
grpc_json_destroy(json->child);
json->child = brother;
grpc_json_destroy(json);
+ gpr_free(scratchpad);
}
int main(int argc, char **argv) {
diff --git a/test/core/statistics/trace_test.c b/test/core/statistics/trace_test.c
index 6eafcf1456..97e1463ae1 100644
--- a/test/core/statistics/trace_test.c
+++ b/test/core/statistics/trace_test.c
@@ -32,10 +32,12 @@
*/
#include <string.h>
+#include <stdio.h>
#include "src/core/statistics/census_interface.h"
#include "src/core/statistics/census_tracing.h"
#include "src/core/statistics/census_tracing.h"
+#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include <grpc/support/sync.h>
@@ -172,6 +174,74 @@ static void test_trace_print(void) {
census_tracing_shutdown();
}
+/* Returns 1 if two ids are equal, otherwise returns 0. */
+static int ids_equal(census_op_id id1, census_op_id id2) {
+ return (id1.upper == id2.upper) && (id1.lower == id2.lower);
+}
+
+static void test_get_active_ops(void) {
+ census_op_id id_1, id_2, id_3;
+ census_trace_obj** active_ops;
+ const char* annotation_txt[] = {"annotation 1", "a2"};
+ int i = 0;
+ int n = 0;
+
+ gpr_log(GPR_INFO, "test_get_active_ops");
+ census_tracing_init();
+ /* No active ops before calling start_op(). */
+ active_ops = census_get_active_ops(&n);
+ GPR_ASSERT(active_ops == NULL);
+ GPR_ASSERT(n == 0);
+
+ /* Starts one op */
+ id_1 = census_tracing_start_op();
+ census_add_method_tag(id_1, "foo_1");
+ active_ops = census_get_active_ops(&n);
+ GPR_ASSERT(active_ops != NULL);
+ GPR_ASSERT(n == 1);
+ GPR_ASSERT(ids_equal(active_ops[0]->id, id_1));
+ census_trace_obj_destroy(active_ops[0]);
+ gpr_free(active_ops);
+ active_ops = NULL;
+
+ /* Start the second and the third ops */
+ id_2 = census_tracing_start_op();
+ census_add_method_tag(id_2, "foo_2");
+ id_3 = census_tracing_start_op();
+ census_add_method_tag(id_3, "foo_3");
+
+ active_ops = census_get_active_ops(&n);
+ GPR_ASSERT(n == 3);
+ for (i = 0; i < 3; i++) {
+ census_trace_obj_destroy(active_ops[i]);
+ }
+ gpr_free(active_ops);
+ active_ops = NULL;
+
+ /* End the second op and add annotations to the third ops*/
+ census_tracing_end_op(id_2);
+ census_tracing_print(id_3, annotation_txt[0]);
+ census_tracing_print(id_3, annotation_txt[1]);
+
+ active_ops = census_get_active_ops(&n);
+ GPR_ASSERT(active_ops != NULL);
+ GPR_ASSERT(n == 2);
+ for (i = 0; i < 2; i++) {
+ census_trace_obj_destroy(active_ops[i]);
+ }
+ gpr_free(active_ops);
+ active_ops = NULL;
+
+ /* End all ops. */
+ census_tracing_end_op(id_1);
+ census_tracing_end_op(id_3);
+ active_ops = census_get_active_ops(&n);
+ GPR_ASSERT(active_ops == NULL);
+ GPR_ASSERT(n == 0);
+
+ census_tracing_shutdown();
+}
+
int main(int argc, char** argv) {
grpc_test_init(argc, argv);
test_init_shutdown();
@@ -180,5 +250,6 @@ int main(int argc, char** argv) {
test_concurrency();
test_add_method_tag_to_unknown_op_id();
test_trace_print();
+ test_get_active_ops();
return 0;
}
diff --git a/test/core/support/env_test.c b/test/core/support/env_test.c
new file mode 100644
index 0000000000..36d7adf80b
--- /dev/null
+++ b/test/core/support/env_test.c
@@ -0,0 +1,64 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+
+#include "src/core/support/env.h"
+#include "src/core/support/string.h"
+#include "test/core/util/test_config.h"
+
+#define LOG_TEST_NAME() gpr_log(GPR_INFO, "%s", __FUNCTION__)
+
+static void test_setenv_getenv(void) {
+ const char *name = "FOO";
+ const char *value = "BAR";
+ char *retrieved_value;
+
+ LOG_TEST_NAME();
+
+ gpr_setenv(name, value);
+ retrieved_value = gpr_getenv(name);
+ GPR_ASSERT(retrieved_value != NULL);
+ GPR_ASSERT(!strcmp(value, retrieved_value));
+ gpr_free(retrieved_value);
+}
+
+int main(int argc, char **argv) {
+ grpc_test_init(argc, argv);
+ test_setenv_getenv();
+ return 0;
+}
diff --git a/test/core/support/file_test.c b/test/core/support/file_test.c
new file mode 100644
index 0000000000..b089954186
--- /dev/null
+++ b/test/core/support/file_test.c
@@ -0,0 +1,159 @@
+/*
+ *
+ * Copyright 2014, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/slice.h>
+
+#include "src/core/support/file.h"
+#include "src/core/support/string.h"
+#include "test/core/util/test_config.h"
+
+#define LOG_TEST_NAME() gpr_log(GPR_INFO, "%s", __FUNCTION__)
+
+static const char prefix[] = "file_test";
+
+static void test_load_empty_file(void) {
+ FILE *tmp = NULL;
+ gpr_slice slice;
+ int success;
+ char *tmp_name;
+
+ LOG_TEST_NAME();
+
+ tmp = gpr_tmpfile(prefix, &tmp_name);
+ GPR_ASSERT(tmp_name != NULL);
+ GPR_ASSERT(tmp != NULL);
+ fclose(tmp);
+
+ slice = gpr_load_file(tmp_name, &success);
+ GPR_ASSERT(success == 1);
+ GPR_ASSERT(GPR_SLICE_LENGTH(slice) == 0);
+
+ remove(tmp_name);
+ gpr_free(tmp_name);
+ gpr_slice_unref(slice);
+}
+
+static void test_load_failure(void) {
+ FILE *tmp = NULL;
+ gpr_slice slice;
+ int success;
+ char *tmp_name;
+
+ LOG_TEST_NAME();
+
+ tmp = gpr_tmpfile(prefix, &tmp_name);
+ GPR_ASSERT(tmp_name != NULL);
+ GPR_ASSERT(tmp != NULL);
+ fclose(tmp);
+ remove(tmp_name);
+
+ slice = gpr_load_file(tmp_name, &success);
+ GPR_ASSERT(success == 0);
+ GPR_ASSERT(GPR_SLICE_LENGTH(slice) == 0);
+ gpr_free(tmp_name);
+ gpr_slice_unref(slice);
+}
+
+static void test_load_small_file(void) {
+ FILE *tmp = NULL;
+ gpr_slice slice;
+ int success;
+ char *tmp_name;
+ const char *blah = "blah";
+
+ LOG_TEST_NAME();
+
+ tmp = gpr_tmpfile(prefix, &tmp_name);
+ GPR_ASSERT(tmp_name != NULL);
+ GPR_ASSERT(tmp != NULL);
+ GPR_ASSERT(fwrite(blah, 1, strlen(blah), tmp) == strlen(blah));
+ fclose(tmp);
+
+ slice = gpr_load_file(tmp_name, &success);
+ GPR_ASSERT(success == 1);
+ GPR_ASSERT(GPR_SLICE_LENGTH(slice) == strlen(blah));
+ GPR_ASSERT(!memcmp(GPR_SLICE_START_PTR(slice), blah, strlen(blah)));
+
+ remove(tmp_name);
+ gpr_free(tmp_name);
+ gpr_slice_unref(slice);
+}
+
+static void test_load_big_file(void) {
+ FILE *tmp = NULL;
+ gpr_slice slice;
+ int success;
+ char *tmp_name;
+ unsigned char buffer[124631];
+ unsigned char *current;
+ size_t i;
+
+ LOG_TEST_NAME();
+
+ for (i = 0; i < sizeof(buffer); i++) {
+ buffer[i] = 42;
+ }
+
+ tmp = gpr_tmpfile(prefix, &tmp_name);
+ GPR_ASSERT(tmp != NULL);
+ GPR_ASSERT(tmp_name != NULL);
+ GPR_ASSERT(fwrite(buffer, 1, sizeof(buffer), tmp) == sizeof(buffer));
+ fclose(tmp);
+
+ slice = gpr_load_file(tmp_name, &success);
+ GPR_ASSERT(success == 1);
+ GPR_ASSERT(GPR_SLICE_LENGTH(slice) == sizeof(buffer));
+ current = GPR_SLICE_START_PTR(slice);
+ for (i = 0; i < sizeof(buffer); i++) {
+ GPR_ASSERT(current[i] == 42);
+ }
+
+ remove(tmp_name);
+ gpr_free(tmp_name);
+ gpr_slice_unref(slice);
+}
+
+
+int main(int argc, char **argv) {
+ grpc_test_init(argc, argv);
+ test_load_empty_file();
+ test_load_failure();
+ test_load_small_file();
+ test_load_big_file();
+ return 0;
+}
diff --git a/test/core/surface/completion_queue_test.c b/test/core/surface/completion_queue_test.c
index dc459d62a8..875cf3e52a 100644
--- a/test/core/surface/completion_queue_test.c
+++ b/test/core/surface/completion_queue_test.c
@@ -105,32 +105,6 @@ static void test_cq_end_read(void) {
shutdown_and_destroy(cc);
}
-static void test_cq_end_invoke_accepted(void) {
- grpc_event *ev;
- grpc_completion_queue *cc;
- int on_finish_called = 0;
- void *tag = create_test_tag();
-
- LOG_TEST();
-
- cc = grpc_completion_queue_create();
-
- grpc_cq_begin_op(cc, NULL, GRPC_INVOKE_ACCEPTED);
- grpc_cq_end_invoke_accepted(cc, tag, NULL, increment_int_on_finish,
- &on_finish_called, GRPC_OP_OK);
-
- ev = grpc_completion_queue_next(cc, gpr_inf_past);
- GPR_ASSERT(ev != NULL);
- GPR_ASSERT(ev->type == GRPC_INVOKE_ACCEPTED);
- GPR_ASSERT(ev->tag == tag);
- GPR_ASSERT(ev->data.invoke_accepted == GRPC_OP_OK);
- GPR_ASSERT(on_finish_called == 0);
- grpc_event_finish(ev);
- GPR_ASSERT(on_finish_called == 1);
-
- shutdown_and_destroy(cc);
-}
-
static void test_cq_end_write_accepted(void) {
grpc_event *ev;
grpc_completion_queue *cc;
@@ -421,7 +395,6 @@ int main(int argc, char **argv) {
test_no_op();
test_wait_empty();
test_cq_end_read();
- test_cq_end_invoke_accepted();
test_cq_end_write_accepted();
test_cq_end_finish_accepted();
test_cq_end_client_metadata_read();
diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc
index a0662fd05f..0fa76f0e02 100644
--- a/test/cpp/interop/client.cc
+++ b/test/cpp/interop/client.cc
@@ -191,10 +191,10 @@ void DoComputeEngineCreds() {
gpr_log(GPR_INFO, "Got username %s", response.username().c_str());
gpr_log(GPR_INFO, "Got oauth_scope %s", response.oauth_scope().c_str());
GPR_ASSERT(!response.username().empty());
- GPR_ASSERT(response.username() == FLAGS_default_service_account);
+ GPR_ASSERT(response.username().c_str() == FLAGS_default_service_account);
GPR_ASSERT(!response.oauth_scope().empty());
- GPR_ASSERT(
- FLAGS_oauth_scope.find(response.oauth_scope()) != grpc::string::npos);
+ const char *oauth_scope_str = response.oauth_scope().c_str();
+ GPR_ASSERT(FLAGS_oauth_scope.find(oauth_scope_str) != grpc::string::npos);
gpr_log(GPR_INFO, "Large unary with compute engine creds done.");
}
@@ -212,8 +212,8 @@ void DoServiceAccountCreds() {
GPR_ASSERT(!response.oauth_scope().empty());
grpc::string json_key = GetServiceAccountJsonKey();
GPR_ASSERT(json_key.find(response.username()) != grpc::string::npos);
- GPR_ASSERT(FLAGS_oauth_scope.find(response.oauth_scope()) !=
- grpc::string::npos);
+ const char *oauth_scope_str = response.oauth_scope().c_str();
+ GPR_ASSERT(FLAGS_oauth_scope.find(oauth_scope_str) != grpc::string::npos);
gpr_log(GPR_INFO, "Large unary with service account creds done.");
}
diff --git a/test/cpp/util/create_test_channel.cc b/test/cpp/util/create_test_channel.cc
index a521162bea..301e9a3c3a 100644
--- a/test/cpp/util/create_test_channel.cc
+++ b/test/cpp/util/create_test_channel.cc
@@ -45,6 +45,8 @@ namespace grpc {
// override_hostname is provided.
// When ssl is not enabled, override_hostname is ignored.
// Set use_prod_root to true to use the SSL root for connecting to google.
+// In this case, path to the roots pem file must be set via environment variable
+// GRPC_DEFAULT_SSL_ROOTS_FILE_PATH.
// Otherwise, root for test SSL cert will be used.
// creds will be used to create a channel when enable_ssl is true.
// Use examples:
@@ -60,7 +62,7 @@ std::shared_ptr<ChannelInterface> CreateTestChannel(
ChannelArguments channel_args;
if (enable_ssl) {
const char* roots_certs =
- use_prod_roots ? prod_roots_certs : test_root_cert;
+ use_prod_roots ? "" : test_root_cert;
SslCredentialsOptions ssl_opts = {roots_certs, "", ""};
std::unique_ptr<Credentials> channel_creds =