Merge branch 'extend_payload_test' of github.com:rjshade/grpc into fix-robbies-thing

reviewable/pr8008/r2^2
Craig Tiller 8 years ago
commit 9017fd551b
  1. 25
      test/core/end2end/cq_verifier.c
  2. 1
      test/core/end2end/cq_verifier.h
  3. 25
      test/core/end2end/tests/payload.c

@ -126,14 +126,14 @@ static gpr_slice merge_slices(gpr_slice *slices, size_t nslices) {
return out; 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; gpr_slice a;
int ok; int ok;
if (!bb) return 0; if (!rbb) return 0;
a = merge_slices(bb->data.raw.slice_buffer.slices, a = merge_slices(rbb->data.raw.slice_buffer.slices,
bb->data.raw.slice_buffer.count); rbb->data.raw.slice_buffer.count);
ok = GPR_SLICE_LENGTH(a) == GPR_SLICE_LENGTH(b) && ok = GPR_SLICE_LENGTH(a) == GPR_SLICE_LENGTH(b) &&
0 == memcmp(GPR_SLICE_START_PTR(a), GPR_SLICE_START_PTR(b), 0 == memcmp(GPR_SLICE_START_PTR(a), GPR_SLICE_START_PTR(b),
GPR_SLICE_LENGTH(a)); GPR_SLICE_LENGTH(a));
@ -142,6 +142,21 @@ static int byte_buffer_eq_slice(grpc_byte_buffer *bb, gpr_slice b) {
return ok; 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) { int byte_buffer_eq_string(grpc_byte_buffer *bb, const char *str) {
grpc_byte_buffer_reader reader; grpc_byte_buffer_reader reader;
grpc_byte_buffer *rbb; 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) && GPR_ASSERT(grpc_byte_buffer_reader_init(&reader, bb) &&
"Couldn't init byte buffer reader"); "Couldn't init byte buffer reader");
rbb = grpc_raw_byte_buffer_from_reader(&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_reader_destroy(&reader);
grpc_byte_buffer_destroy(rbb); grpc_byte_buffer_destroy(rbb);

@ -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) \ #define CQ_EXPECT_COMPLETION(v, tag, success) \
cq_expect_completion(v, __FILE__, __LINE__, 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 byte_buffer_eq_string(grpc_byte_buffer *byte_buffer, const char *string);
int contains_metadata(grpc_metadata_array *array, const char *key, int contains_metadata(grpc_metadata_array *array, const char *key,
const char *value); const char *value);

@ -95,9 +95,25 @@ static void end_test(grpc_end2end_test_fixture *f) {
grpc_completion_queue_destroy(f->cq); 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) { static void request_response_with_payload(grpc_end2end_test_fixture f) {
gpr_slice request_payload_slice = gpr_slice_from_copied_string("hello world"); /* Create large request and response bodies. These are big enough to require
gpr_slice response_payload_slice = gpr_slice_from_copied_string("hello you"); * 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 *c;
grpc_call *s; grpc_call *s;
grpc_byte_buffer *request_payload = 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.method, "/foo"));
GPR_ASSERT(0 == strcmp(call_details.host, "foo.test.google.fr")); GPR_ASSERT(0 == strcmp(call_details.host, "foo.test.google.fr"));
GPR_ASSERT(was_cancelled == 0); GPR_ASSERT(was_cancelled == 0);
GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, "hello world")); GPR_ASSERT(byte_buffer_eq_slice(request_payload_recv, request_payload_slice));
GPR_ASSERT(byte_buffer_eq_string(response_payload_recv, "hello you")); GPR_ASSERT(
byte_buffer_eq_slice(response_payload_recv, response_payload_slice));
gpr_free(details); gpr_free(details);
grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&initial_metadata_recv);

Loading…
Cancel
Save