Add new end2end test for channelz

reviewable/pr15343/r8
ncteisen 7 years ago
parent 9b488f788b
commit b8a52e0cf3
  1. 2
      CMakeLists.txt
  2. 2
      Makefile
  3. 1
      gRPC-Core.podspec
  4. 2
      grpc.gyp
  5. 12
      src/core/lib/channel/channelz.cc
  6. 1
      test/core/channel/channelz_test.cc
  7. 8
      test/core/end2end/end2end_nosec_tests.cc
  8. 8
      test/core/end2end/end2end_tests.cc
  9. 1
      test/core/end2end/gen_build_yaml.py
  10. 1
      test/core/end2end/generate_tests.bzl
  11. 263
      test/core/end2end/tests/channelz.cc
  12. 24
      test/core/end2end/tests/simple_request.cc
  13. 2
      tools/run_tests/generated/sources_and_headers.json
  14. 927
      tools/run_tests/generated/tests.json

@ -5281,6 +5281,7 @@ add_library(end2end_tests
test/core/end2end/tests/cancel_before_invoke.cc
test/core/end2end/tests/cancel_in_a_vacuum.cc
test/core/end2end/tests/cancel_with_status.cc
test/core/end2end/tests/channelz.cc
test/core/end2end/tests/compressed_payload.cc
test/core/end2end/tests/connectivity.cc
test/core/end2end/tests/default_host.cc
@ -5399,6 +5400,7 @@ add_library(end2end_nosec_tests
test/core/end2end/tests/cancel_before_invoke.cc
test/core/end2end/tests/cancel_in_a_vacuum.cc
test/core/end2end/tests/cancel_with_status.cc
test/core/end2end/tests/channelz.cc
test/core/end2end/tests/compressed_payload.cc
test/core/end2end/tests/connectivity.cc
test/core/end2end/tests/default_host.cc

@ -9979,6 +9979,7 @@ LIBEND2END_TESTS_SRC = \
test/core/end2end/tests/cancel_before_invoke.cc \
test/core/end2end/tests/cancel_in_a_vacuum.cc \
test/core/end2end/tests/cancel_with_status.cc \
test/core/end2end/tests/channelz.cc \
test/core/end2end/tests/compressed_payload.cc \
test/core/end2end/tests/connectivity.cc \
test/core/end2end/tests/default_host.cc \
@ -10095,6 +10096,7 @@ LIBEND2END_NOSEC_TESTS_SRC = \
test/core/end2end/tests/cancel_before_invoke.cc \
test/core/end2end/tests/cancel_in_a_vacuum.cc \
test/core/end2end/tests/cancel_with_status.cc \
test/core/end2end/tests/channelz.cc \
test/core/end2end/tests/compressed_payload.cc \
test/core/end2end/tests/connectivity.cc \
test/core/end2end/tests/default_host.cc \

@ -1178,6 +1178,7 @@ Pod::Spec.new do |s|
'test/core/end2end/tests/cancel_before_invoke.cc',
'test/core/end2end/tests/cancel_in_a_vacuum.cc',
'test/core/end2end/tests/cancel_with_status.cc',
'test/core/end2end/tests/channelz.cc',
'test/core/end2end/tests/compressed_payload.cc',
'test/core/end2end/tests/connectivity.cc',
'test/core/end2end/tests/default_host.cc',

@ -2611,6 +2611,7 @@
'test/core/end2end/tests/cancel_before_invoke.cc',
'test/core/end2end/tests/cancel_in_a_vacuum.cc',
'test/core/end2end/tests/cancel_with_status.cc',
'test/core/end2end/tests/channelz.cc',
'test/core/end2end/tests/compressed_payload.cc',
'test/core/end2end/tests/connectivity.cc',
'test/core/end2end/tests/default_host.cc',
@ -2701,6 +2702,7 @@
'test/core/end2end/tests/cancel_before_invoke.cc',
'test/core/end2end/tests/cancel_in_a_vacuum.cc',
'test/core/end2end/tests/cancel_with_status.cc',
'test/core/end2end/tests/channelz.cc',
'test/core/end2end/tests/compressed_payload.cc',
'test/core/end2end/tests/connectivity.cc',
'test/core/end2end/tests/default_host.cc',

@ -164,12 +164,12 @@ char* Channel::RenderJSON() {
json_iterator = nullptr;
// We use -1 as sentinel values since proto default value for integers is
// zero, and the confuses the parser into thinking the value weren't present
json_iterator = add_num_str(json, json_iterator, "callsStarted",
calls_started_);
json_iterator = add_num_str(json, json_iterator, "callsSucceeded",
calls_succeeded_);
json_iterator = add_num_str(json, json_iterator, "callsFailed",
calls_failed_);
json_iterator =
add_num_str(json, json_iterator, "callsStarted", calls_started_);
json_iterator =
add_num_str(json, json_iterator, "callsSucceeded", calls_succeeded_);
json_iterator =
add_num_str(json, json_iterator, "callsFailed", calls_failed_);
gpr_timespec ts =
grpc_millis_to_timespec(last_call_started_millis_, GPR_CLOCK_REALTIME);
json_iterator =

@ -116,7 +116,6 @@ void ValidateChannel(Channel* channel, validate_channel_data_args args) {
grpc::testing::ValidateChannelProtoJsonTranslation(json_str);
ValidateCounters(json_str, args);
gpr_free(json_str);
}
grpc_millis GetLastCallStartedMillis(Channel* channel) {

@ -54,6 +54,8 @@ extern void cancel_in_a_vacuum(grpc_end2end_test_config config);
extern void cancel_in_a_vacuum_pre_init(void);
extern void cancel_with_status(grpc_end2end_test_config config);
extern void cancel_with_status_pre_init(void);
extern void channelz(grpc_end2end_test_config config);
extern void channelz_pre_init(void);
extern void compressed_payload(grpc_end2end_test_config config);
extern void compressed_payload_pre_init(void);
extern void connectivity(grpc_end2end_test_config config);
@ -199,6 +201,7 @@ void grpc_end2end_tests_pre_init(void) {
cancel_before_invoke_pre_init();
cancel_in_a_vacuum_pre_init();
cancel_with_status_pre_init();
channelz_pre_init();
compressed_payload_pre_init();
connectivity_pre_init();
default_host_pre_init();
@ -284,6 +287,7 @@ void grpc_end2end_tests(int argc, char **argv,
cancel_before_invoke(config);
cancel_in_a_vacuum(config);
cancel_with_status(config);
channelz(config);
compressed_payload(config);
connectivity(config);
default_host(config);
@ -400,6 +404,10 @@ void grpc_end2end_tests(int argc, char **argv,
cancel_with_status(config);
continue;
}
if (0 == strcmp("channelz", argv[i])) {
channelz(config);
continue;
}
if (0 == strcmp("compressed_payload", argv[i])) {
compressed_payload(config);
continue;

@ -56,6 +56,8 @@ extern void cancel_in_a_vacuum(grpc_end2end_test_config config);
extern void cancel_in_a_vacuum_pre_init(void);
extern void cancel_with_status(grpc_end2end_test_config config);
extern void cancel_with_status_pre_init(void);
extern void channelz(grpc_end2end_test_config config);
extern void channelz_pre_init(void);
extern void compressed_payload(grpc_end2end_test_config config);
extern void compressed_payload_pre_init(void);
extern void connectivity(grpc_end2end_test_config config);
@ -202,6 +204,7 @@ void grpc_end2end_tests_pre_init(void) {
cancel_before_invoke_pre_init();
cancel_in_a_vacuum_pre_init();
cancel_with_status_pre_init();
channelz_pre_init();
compressed_payload_pre_init();
connectivity_pre_init();
default_host_pre_init();
@ -288,6 +291,7 @@ void grpc_end2end_tests(int argc, char **argv,
cancel_before_invoke(config);
cancel_in_a_vacuum(config);
cancel_with_status(config);
channelz(config);
compressed_payload(config);
connectivity(config);
default_host(config);
@ -408,6 +412,10 @@ void grpc_end2end_tests(int argc, char **argv,
cancel_with_status(config);
continue;
}
if (0 == strcmp("channelz", argv[i])) {
channelz(config);
continue;
}
if (0 == strcmp("compressed_payload", argv[i])) {
compressed_payload(config);
continue;

@ -106,6 +106,7 @@ END2END_TESTS = {
needs_compression=True),
'connectivity': connectivity_test_options._replace(needs_names=True,
proxyable=False, cpu_cost=LOWCPU, exclude_iomgrs=['uv']),
'channelz': default_test_options,
'default_host': default_test_options._replace(
needs_fullstack=True, needs_dns=True, needs_names=True),
'call_host_override': default_test_options._replace(

@ -113,6 +113,7 @@ END2END_TESTS = {
'compressed_payload': test_options(proxyable=False, exclude_inproc=True),
'connectivity': test_options(needs_fullstack=True, needs_names=True,
proxyable=False),
'channelz': test_options(),
'default_host': test_options(needs_fullstack=True, needs_dns=True,
needs_names=True),
'disappearing_server': test_options(needs_fullstack=True,needs_names=True),

@ -0,0 +1,263 @@
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "test/core/end2end/end2end_tests.h"
#include <stdio.h>
#include <string.h>
#include "src/core/lib/surface/channel.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>
#include "src/core/lib/gpr/string.h"
#include "test/core/end2end/cq_verifier.h"
static void* tag(intptr_t 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, "Running test: %s/%s", test_name, config.name);
f = config.create_fixture(client_args, server_args);
config.init_server(&f, server_args);
config.init_client(&f, client_args);
return f;
}
static gpr_timespec n_seconds_from_now(int n) {
return grpc_timeout_seconds_to_deadline(n);
}
static gpr_timespec five_seconds_from_now(void) {
return n_seconds_from_now(5);
}
static void drain_cq(grpc_completion_queue* cq) {
grpc_event ev;
do {
ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr);
} while (ev.type != GRPC_QUEUE_SHUTDOWN);
}
static void shutdown_server(grpc_end2end_test_fixture* f) {
if (!f->server) return;
grpc_server_shutdown_and_notify(f->server, f->shutdown_cq, tag(1000));
GPR_ASSERT(grpc_completion_queue_pluck(f->shutdown_cq, tag(1000),
grpc_timeout_seconds_to_deadline(5),
nullptr)
.type == GRPC_OP_COMPLETE);
grpc_server_destroy(f->server);
f->server = nullptr;
}
static void shutdown_client(grpc_end2end_test_fixture* f) {
if (!f->client) return;
grpc_channel_destroy(f->client);
f->client = nullptr;
}
static void end_test(grpc_end2end_test_fixture* f) {
shutdown_server(f);
shutdown_client(f);
grpc_completion_queue_shutdown(f->cq);
drain_cq(f->cq);
grpc_completion_queue_destroy(f->cq);
grpc_completion_queue_destroy(f->shutdown_cq);
}
static void run_one_request(grpc_end2end_test_config config,
grpc_end2end_test_fixture f,
bool request_is_success) {
grpc_call* c;
grpc_call* s;
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_call_details call_details;
grpc_status_code status;
grpc_call_error error;
grpc_slice details;
int was_cancelled = 2;
gpr_timespec deadline = five_seconds_from_now();
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_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_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.error_string = nullptr;
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_SEND_STATUS_FROM_SERVER;
op->data.send_status_from_server.trailing_metadata_count = 0;
op->data.send_status_from_server.status =
request_is_success ? GRPC_STATUS_OK : GRPC_STATUS_UNIMPLEMENTED;
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++;
op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
op->data.recv_close_on_server.cancelled = &was_cancelled;
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_EXPECT_COMPLETION(cqv, tag(1), 1);
cq_verify(cqv);
GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz"));
GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo"));
GPR_ASSERT(0 == call_details.flags);
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);
}
static void test_channelz(grpc_end2end_test_config config) {
grpc_end2end_test_fixture f;
f = begin_test(config, "test_channelz", nullptr, nullptr);
grpc_core::channelz::Channel* channelz_channel =
grpc_channel_get_channelz_node(f.client);
char* json = channelz_channel->RenderJSON();
GPR_ASSERT(nullptr != strstr(json, "\"callsStarted\":\"0\""));
GPR_ASSERT(nullptr != strstr(json, "\"callsFailed\":\"0\""));
GPR_ASSERT(nullptr != strstr(json, "\"callsSucceeded\":\"0\""));
gpr_free(json);
// one successful request
run_one_request(config, f, true);
json = channelz_channel->RenderJSON();
GPR_ASSERT(nullptr != strstr(json, "\"callsStarted\":\"1\""));
GPR_ASSERT(nullptr != strstr(json, "\"callsFailed\":\"0\""));
GPR_ASSERT(nullptr != strstr(json, "\"callsSucceeded\":\"1\""));
gpr_free(json);
// one failed request
run_one_request(config, f, false);
json = channelz_channel->RenderJSON();
gpr_log(GPR_INFO, "%s", json);
GPR_ASSERT(nullptr != strstr(json, "\"callsStarted\":\"2\""));
GPR_ASSERT(nullptr != strstr(json, "\"callsFailed\":\"1\""));
GPR_ASSERT(nullptr != strstr(json, "\"callsSucceeded\":\"1\""));
gpr_free(json);
end_test(&f);
config.tear_down_data(&f);
}
static void test_channelz_with_channel_trace(grpc_end2end_test_config config) {
grpc_end2end_test_fixture f;
grpc_arg client_a;
client_a.type = GRPC_ARG_INTEGER;
client_a.key = const_cast<char*>(GRPC_ARG_MAX_CHANNEL_TRACE_EVENTS_PER_NODE);
client_a.value.integer = 5;
grpc_channel_args client_args = {1, &client_a};
f = begin_test(config, "test_channelz_with_channel_trace", &client_args,
nullptr);
grpc_core::channelz::Channel* channelz_channel =
grpc_channel_get_channelz_node(f.client);
char* json = channelz_channel->RenderJSON();
gpr_log(GPR_INFO, "%s", json);
GPR_ASSERT(nullptr != strstr(json, "\"trace\""));
GPR_ASSERT(nullptr != strstr(json, "\"description\":\"Channel created\""));
GPR_ASSERT(nullptr != strstr(json, "\"severity\":\"CT_INFO\""));
gpr_free(json);
end_test(&f);
config.tear_down_data(&f);
}
void channelz(grpc_end2end_test_config config) {
test_channelz(config);
test_channelz_with_channel_trace(config);
}
void channelz_pre_init(void) {}

@ -21,8 +21,6 @@
#include <stdio.h>
#include <string.h>
#include "src/core/lib/surface/channel.h"
#include <grpc/byte_buffer.h>
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
@ -254,18 +252,6 @@ static void test_invoke_simple_request(grpc_end2end_test_config config) {
f = begin_test(config, "test_invoke_simple_request", nullptr, nullptr);
simple_request_body(config, f);
// The following is a quick sanity check on channelz functionality. It
// ensures that core properly tracked the one call that occurred in this
// simple end2end test.
grpc_core::channelz::Channel* channelz_channel =
grpc_channel_get_channelz_node(f.client);
char* json = channelz_channel->RenderJSON();
GPR_ASSERT(nullptr != strstr(json, "\"callsStarted\":\"1\""));
GPR_ASSERT(nullptr != strstr(json, "\"callsFailed\":\"1\""));
GPR_ASSERT(nullptr != strstr(json, "\"callsSucceeded\":\"0\""));
gpr_free(json);
end_test(&f);
config.tear_down_data(&f);
}
@ -278,16 +264,6 @@ static void test_invoke_10_simple_requests(grpc_end2end_test_config config) {
simple_request_body(config, f);
gpr_log(GPR_INFO, "Running test: Passed simple request %d", i);
}
// The following is a quick sanity check on channelz functionality. It
// ensures that core properly tracked the ten calls that occurred.
grpc_core::channelz::Channel* channelz_channel =
grpc_channel_get_channelz_node(f.client);
char* json = channelz_channel->RenderJSON();
GPR_ASSERT(nullptr != strstr(json, "\"callsStarted\":\"10\""));
GPR_ASSERT(nullptr != strstr(json, "\"callsFailed\":\"10\""));
GPR_ASSERT(nullptr != strstr(json, "\"callsSucceeded\":\"0\""));
gpr_free(json);
end_test(&f);
config.tear_down_data(&f);
}

@ -8744,6 +8744,7 @@
"test/core/end2end/tests/cancel_in_a_vacuum.cc",
"test/core/end2end/tests/cancel_test_helpers.h",
"test/core/end2end/tests/cancel_with_status.cc",
"test/core/end2end/tests/channelz.cc",
"test/core/end2end/tests/compressed_payload.cc",
"test/core/end2end/tests/connectivity.cc",
"test/core/end2end/tests/default_host.cc",
@ -8843,6 +8844,7 @@
"test/core/end2end/tests/cancel_in_a_vacuum.cc",
"test/core/end2end/tests/cancel_test_helpers.h",
"test/core/end2end/tests/cancel_with_status.cc",
"test/core/end2end/tests/channelz.cc",
"test/core/end2end/tests/compressed_payload.cc",
"test/core/end2end/tests/connectivity.cc",
"test/core/end2end/tests/default_host.cc",

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save