|
|
@ -196,6 +196,178 @@ static void run_one_request(grpc_end2end_test_config config, |
|
|
|
cq_verifier_destroy(cqv); |
|
|
|
cq_verifier_destroy(cqv); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Creates and returns a grpc_slice containing random alphanumeric characters.
|
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
static grpc_slice generate_random_slice() { |
|
|
|
|
|
|
|
size_t i; |
|
|
|
|
|
|
|
static const char chars[] = "abcdefghijklmnopqrstuvwxyz1234567890"; |
|
|
|
|
|
|
|
char* output; |
|
|
|
|
|
|
|
const size_t output_size = 1024 * 1024; |
|
|
|
|
|
|
|
output = static_cast<char*>(gpr_malloc(output_size)); |
|
|
|
|
|
|
|
for (i = 0; i < output_size - 1; ++i) { |
|
|
|
|
|
|
|
output[i] = chars[rand() % static_cast<int>(sizeof(chars) - 1)]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
output[output_size - 1] = '\0'; |
|
|
|
|
|
|
|
grpc_slice out = grpc_slice_from_copied_string(output); |
|
|
|
|
|
|
|
gpr_free(output); |
|
|
|
|
|
|
|
return out; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void run_one_request_with_payload(grpc_end2end_test_config config, |
|
|
|
|
|
|
|
grpc_end2end_test_fixture f) { |
|
|
|
|
|
|
|
/* 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. */ |
|
|
|
|
|
|
|
grpc_slice request_payload_slice = generate_random_slice(); |
|
|
|
|
|
|
|
grpc_slice response_payload_slice = generate_random_slice(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
grpc_call* c; |
|
|
|
|
|
|
|
grpc_call* s; |
|
|
|
|
|
|
|
grpc_byte_buffer* request_payload = |
|
|
|
|
|
|
|
grpc_raw_byte_buffer_create(&request_payload_slice, 1); |
|
|
|
|
|
|
|
grpc_byte_buffer* response_payload = |
|
|
|
|
|
|
|
grpc_raw_byte_buffer_create(&response_payload_slice, 1); |
|
|
|
|
|
|
|
cq_verifier* cqv = cq_verifier_create(f.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 = nullptr; |
|
|
|
|
|
|
|
grpc_byte_buffer* response_payload_recv = nullptr; |
|
|
|
|
|
|
|
grpc_call_details call_details; |
|
|
|
|
|
|
|
grpc_status_code status; |
|
|
|
|
|
|
|
grpc_call_error error; |
|
|
|
|
|
|
|
grpc_slice details; |
|
|
|
|
|
|
|
int was_cancelled = 2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gpr_timespec deadline = n_seconds_from_now(60); |
|
|
|
|
|
|
|
c = grpc_channel_create_call(f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq, |
|
|
|
|
|
|
|
grpc_slice_from_static_string("/foo"), nullptr, |
|
|
|
|
|
|
|
deadline, nullptr); |
|
|
|
|
|
|
|
GPR_ASSERT(c); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
memset(ops, 0, sizeof(ops)); |
|
|
|
|
|
|
|
op = ops; |
|
|
|
|
|
|
|
op->op = GRPC_OP_SEND_INITIAL_METADATA; |
|
|
|
|
|
|
|
op->data.send_initial_metadata.count = 0; |
|
|
|
|
|
|
|
op->flags = 0; |
|
|
|
|
|
|
|
op->reserved = nullptr; |
|
|
|
|
|
|
|
op++; |
|
|
|
|
|
|
|
op->op = GRPC_OP_SEND_MESSAGE; |
|
|
|
|
|
|
|
op->data.send_message.send_message = request_payload; |
|
|
|
|
|
|
|
op->flags = 0; |
|
|
|
|
|
|
|
op->reserved = nullptr; |
|
|
|
|
|
|
|
op++; |
|
|
|
|
|
|
|
op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; |
|
|
|
|
|
|
|
op->flags = 0; |
|
|
|
|
|
|
|
op->reserved = nullptr; |
|
|
|
|
|
|
|
op++; |
|
|
|
|
|
|
|
op->op = GRPC_OP_RECV_INITIAL_METADATA; |
|
|
|
|
|
|
|
op->data.recv_initial_metadata.recv_initial_metadata = &initial_metadata_recv; |
|
|
|
|
|
|
|
op->flags = 0; |
|
|
|
|
|
|
|
op->reserved = nullptr; |
|
|
|
|
|
|
|
op++; |
|
|
|
|
|
|
|
op->op = GRPC_OP_RECV_MESSAGE; |
|
|
|
|
|
|
|
op->data.recv_message.recv_message = &response_payload_recv; |
|
|
|
|
|
|
|
op->flags = 0; |
|
|
|
|
|
|
|
op->reserved = nullptr; |
|
|
|
|
|
|
|
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->flags = 0; |
|
|
|
|
|
|
|
op->reserved = nullptr; |
|
|
|
|
|
|
|
op++; |
|
|
|
|
|
|
|
error = grpc_call_start_batch(c, ops, static_cast<size_t>(op - ops), tag(1), |
|
|
|
|
|
|
|
nullptr); |
|
|
|
|
|
|
|
GPR_ASSERT(GRPC_CALL_OK == error); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
error = |
|
|
|
|
|
|
|
grpc_server_request_call(f.server, &s, &call_details, |
|
|
|
|
|
|
|
&request_metadata_recv, f.cq, f.cq, tag(101)); |
|
|
|
|
|
|
|
GPR_ASSERT(GRPC_CALL_OK == error); |
|
|
|
|
|
|
|
CQ_EXPECT_COMPLETION(cqv, tag(101), 1); |
|
|
|
|
|
|
|
cq_verify(cqv); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
memset(ops, 0, sizeof(ops)); |
|
|
|
|
|
|
|
op = ops; |
|
|
|
|
|
|
|
op->op = GRPC_OP_SEND_INITIAL_METADATA; |
|
|
|
|
|
|
|
op->data.send_initial_metadata.count = 0; |
|
|
|
|
|
|
|
op->flags = 0; |
|
|
|
|
|
|
|
op->reserved = nullptr; |
|
|
|
|
|
|
|
op++; |
|
|
|
|
|
|
|
op->op = GRPC_OP_RECV_MESSAGE; |
|
|
|
|
|
|
|
op->data.recv_message.recv_message = &request_payload_recv; |
|
|
|
|
|
|
|
op->flags = 0; |
|
|
|
|
|
|
|
op->reserved = nullptr; |
|
|
|
|
|
|
|
op++; |
|
|
|
|
|
|
|
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(102), |
|
|
|
|
|
|
|
nullptr); |
|
|
|
|
|
|
|
GPR_ASSERT(GRPC_CALL_OK == error); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CQ_EXPECT_COMPLETION(cqv, tag(102), 1); |
|
|
|
|
|
|
|
cq_verify(cqv); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
memset(ops, 0, sizeof(ops)); |
|
|
|
|
|
|
|
op = ops; |
|
|
|
|
|
|
|
op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; |
|
|
|
|
|
|
|
op->data.recv_close_on_server.cancelled = &was_cancelled; |
|
|
|
|
|
|
|
op->flags = 0; |
|
|
|
|
|
|
|
op->reserved = nullptr; |
|
|
|
|
|
|
|
op++; |
|
|
|
|
|
|
|
op->op = GRPC_OP_SEND_MESSAGE; |
|
|
|
|
|
|
|
op->data.send_message.send_message = response_payload; |
|
|
|
|
|
|
|
op->flags = 0; |
|
|
|
|
|
|
|
op->reserved = nullptr; |
|
|
|
|
|
|
|
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_OK; |
|
|
|
|
|
|
|
grpc_slice status_details = grpc_slice_from_static_string("xyz"); |
|
|
|
|
|
|
|
op->data.send_status_from_server.status_details = &status_details; |
|
|
|
|
|
|
|
op->flags = 0; |
|
|
|
|
|
|
|
op->reserved = nullptr; |
|
|
|
|
|
|
|
op++; |
|
|
|
|
|
|
|
error = grpc_call_start_batch(s, ops, static_cast<size_t>(op - ops), tag(103), |
|
|
|
|
|
|
|
nullptr); |
|
|
|
|
|
|
|
GPR_ASSERT(GRPC_CALL_OK == error); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CQ_EXPECT_COMPLETION(cqv, tag(103), 1); |
|
|
|
|
|
|
|
CQ_EXPECT_COMPLETION(cqv, tag(1), 1); |
|
|
|
|
|
|
|
cq_verify(cqv); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GPR_ASSERT(status == GRPC_STATUS_OK); |
|
|
|
|
|
|
|
GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); |
|
|
|
|
|
|
|
GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); |
|
|
|
|
|
|
|
GPR_ASSERT(was_cancelled == 0); |
|
|
|
|
|
|
|
GPR_ASSERT(byte_buffer_eq_slice(request_payload_recv, request_payload_slice)); |
|
|
|
|
|
|
|
GPR_ASSERT( |
|
|
|
|
|
|
|
byte_buffer_eq_slice(response_payload_recv, response_payload_slice)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
grpc_slice_unref(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_unref(c); |
|
|
|
|
|
|
|
grpc_call_unref(s); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cq_verifier_destroy(cqv); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void test_channelz(grpc_end2end_test_config config) { |
|
|
|
static void test_channelz(grpc_end2end_test_config config) { |
|
|
|
grpc_end2end_test_fixture f; |
|
|
|
grpc_end2end_test_fixture f; |
|
|
|
|
|
|
|
|
|
|
@ -258,6 +430,10 @@ static void test_channelz(grpc_end2end_test_config config) { |
|
|
|
GPR_ASSERT(nullptr == strstr(json, "\"severity\":\"CT_INFO\"")); |
|
|
|
GPR_ASSERT(nullptr == strstr(json, "\"severity\":\"CT_INFO\"")); |
|
|
|
gpr_free(json); |
|
|
|
gpr_free(json); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// one successful request with payload to test socket data
|
|
|
|
|
|
|
|
// TODO(ncteisen): add some programatic spot checks on the socket json.
|
|
|
|
|
|
|
|
run_one_request_with_payload(config, f); |
|
|
|
|
|
|
|
|
|
|
|
end_test(&f); |
|
|
|
end_test(&f); |
|
|
|
config.tear_down_data(&f); |
|
|
|
config.tear_down_data(&f); |
|
|
|
} |
|
|
|
} |
|
|
|