aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/end2end
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2016-09-09 15:49:44 -0700
committerGravatar Craig Tiller <ctiller@google.com>2016-09-09 15:49:44 -0700
commit9017fd551b70eec01ff52740ca8e0228391de553 (patch)
tree772fa538d825c4f3d40396cd6180f234feb22e57 /test/core/end2end
parented9880d19fc3c6cbdb9dca21d0fcf0677aea88b9 (diff)
parentd5d851baf3dbdf92b1c1946c6c46334e6d095b3d (diff)
Merge branch 'extend_payload_test' of github.com:rjshade/grpc into fix-robbies-thing
Diffstat (limited to 'test/core/end2end')
-rw-r--r--test/core/end2end/cq_verifier.c25
-rw-r--r--test/core/end2end/cq_verifier.h1
-rw-r--r--test/core/end2end/tests/payload.c25
3 files changed, 42 insertions, 9 deletions
diff --git a/test/core/end2end/cq_verifier.c b/test/core/end2end/cq_verifier.c
index 1f42d3457e..3e7e3f22a2 100644
--- a/test/core/end2end/cq_verifier.c
+++ b/test/core/end2end/cq_verifier.c
@@ -126,14 +126,14 @@ static gpr_slice merge_slices(gpr_slice *slices, size_t nslices) {
return out;
}
-static int byte_buffer_eq_slice(grpc_byte_buffer *bb, gpr_slice b) {
+int raw_byte_buffer_eq_slice(grpc_byte_buffer *rbb, gpr_slice b) {
gpr_slice a;
int ok;
- if (!bb) return 0;
+ if (!rbb) return 0;
- a = merge_slices(bb->data.raw.slice_buffer.slices,
- bb->data.raw.slice_buffer.count);
+ a = merge_slices(rbb->data.raw.slice_buffer.slices,
+ rbb->data.raw.slice_buffer.count);
ok = GPR_SLICE_LENGTH(a) == GPR_SLICE_LENGTH(b) &&
0 == memcmp(GPR_SLICE_START_PTR(a), GPR_SLICE_START_PTR(b),
GPR_SLICE_LENGTH(a));
@@ -142,6 +142,21 @@ static int byte_buffer_eq_slice(grpc_byte_buffer *bb, gpr_slice b) {
return ok;
}
+int byte_buffer_eq_slice(grpc_byte_buffer *bb, gpr_slice b) {
+ grpc_byte_buffer_reader reader;
+ grpc_byte_buffer *rbb;
+ int res;
+
+ GPR_ASSERT(grpc_byte_buffer_reader_init(&reader, bb) &&
+ "Couldn't init byte buffer reader");
+ rbb = grpc_raw_byte_buffer_from_reader(&reader);
+ res = raw_byte_buffer_eq_slice(rbb, b);
+ grpc_byte_buffer_reader_destroy(&reader);
+ grpc_byte_buffer_destroy(rbb);
+
+ return res;
+}
+
int byte_buffer_eq_string(grpc_byte_buffer *bb, const char *str) {
grpc_byte_buffer_reader reader;
grpc_byte_buffer *rbb;
@@ -150,7 +165,7 @@ int byte_buffer_eq_string(grpc_byte_buffer *bb, const char *str) {
GPR_ASSERT(grpc_byte_buffer_reader_init(&reader, bb) &&
"Couldn't init byte buffer reader");
rbb = grpc_raw_byte_buffer_from_reader(&reader);
- res = byte_buffer_eq_slice(rbb, gpr_slice_from_copied_string(str));
+ res = raw_byte_buffer_eq_slice(rbb, gpr_slice_from_copied_string(str));
grpc_byte_buffer_reader_destroy(&reader);
grpc_byte_buffer_destroy(rbb);
diff --git a/test/core/end2end/cq_verifier.h b/test/core/end2end/cq_verifier.h
index 0a7c03c090..47464fa319 100644
--- a/test/core/end2end/cq_verifier.h
+++ b/test/core/end2end/cq_verifier.h
@@ -67,6 +67,7 @@ void cq_expect_completion(cq_verifier *v, const char *file, int line, void *tag,
#define CQ_EXPECT_COMPLETION(v, tag, success) \
cq_expect_completion(v, __FILE__, __LINE__, tag, success)
+int byte_buffer_eq_slice(grpc_byte_buffer *bb, gpr_slice b);
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);
diff --git a/test/core/end2end/tests/payload.c b/test/core/end2end/tests/payload.c
index c71704ff61..c37d7fe41a 100644
--- a/test/core/end2end/tests/payload.c
+++ b/test/core/end2end/tests/payload.c
@@ -95,9 +95,25 @@ static void end_test(grpc_end2end_test_fixture *f) {
grpc_completion_queue_destroy(f->cq);
}
+/* Creates and returns a gpr_slice containing random alphanumeric characters. */
+static gpr_slice generate_random_slice() {
+ size_t i;
+ static const char chars[] = "abcdefghijklmnopqrstuvwxyz1234567890";
+ char output[1024 * 1024]; /* 1 MB */
+ for (i = 0; i < 1024 * 1024 - 1; ++i) {
+ output[i] = chars[rand() % (int)(sizeof(chars) - 1)];
+ }
+ output[1024 * 1024 - 1] = '\0';
+ return gpr_slice_from_copied_string(output);
+}
+
static void request_response_with_payload(grpc_end2end_test_fixture f) {
- gpr_slice request_payload_slice = gpr_slice_from_copied_string("hello world");
- gpr_slice response_payload_slice = gpr_slice_from_copied_string("hello you");
+ /* Create large request and response bodies. These are big enough to require
+ * multiple round trips to deliver to the peer, and their exact contents of
+ * will be verified on completion. */
+ gpr_slice request_payload_slice = generate_random_slice();
+ gpr_slice response_payload_slice = generate_random_slice();
+
grpc_call *c;
grpc_call *s;
grpc_byte_buffer *request_payload =
@@ -222,8 +238,9 @@ static void request_response_with_payload(grpc_end2end_test_fixture f) {
GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
GPR_ASSERT(0 == strcmp(call_details.host, "foo.test.google.fr"));
GPR_ASSERT(was_cancelled == 0);
- GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, "hello world"));
- GPR_ASSERT(byte_buffer_eq_string(response_payload_recv, "hello you"));
+ GPR_ASSERT(byte_buffer_eq_slice(request_payload_recv, request_payload_slice));
+ GPR_ASSERT(
+ byte_buffer_eq_slice(response_payload_recv, response_payload_slice));
gpr_free(details);
grpc_metadata_array_destroy(&initial_metadata_recv);