Extends the payload test to use large random bodies.

pull/7415/head
Robbie Shade 9 years ago
parent 69d897d032
commit 2449e193bb
  1. 2
      test/core/end2end/cq_verifier.c
  2. 1
      test/core/end2end/cq_verifier.h
  3. 27
      test/core/end2end/tests/payload.c

@ -128,7 +128,7 @@ 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 byte_buffer_eq_slice(grpc_byte_buffer *bb, gpr_slice b) {
gpr_slice a;
int ok;

@ -61,6 +61,7 @@ void cq_verify_empty(cq_verifier *v);
the event. */
void cq_expect_completion(cq_verifier *v, void *tag, bool 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);

@ -97,9 +97,27 @@ static void end_test(grpc_end2end_test_fixture *f) {
grpc_completion_queue_destroy(f->cq);
}
/* Creates and returns a gpr_slice of specified length, containing random
* alphanumeric characters. */
static gpr_slice generate_random_slice(int length_bytes) {
int i;
gpr_slice slice = gpr_slice_malloc(length_bytes);
static const char alphanum[] = "abcdefghijklmnopqrstuvwxyz01234567890";
for (i = 0; i < length_bytes; ++i) {
*(GPR_SLICE_START_PTR(slice) + i) =
alphanum[rand() % (sizeof(alphanum) - 1)];
}
return slice;
}
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. */
int payload_size_bytes = 1024 * 1024; /* 1 MB */
gpr_slice request_payload_slice = generate_random_slice(payload_size_bytes);
gpr_slice response_payload_slice = generate_random_slice(payload_size_bytes);
grpc_call *c;
grpc_call *s;
grpc_byte_buffer *request_payload =
@ -224,8 +242,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);

Loading…
Cancel
Save