diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/core/end2end/tests/channel_connectivity.c | 25 | ||||
-rw-r--r-- | test/core/iomgr/sockaddr_utils_test.c | 14 | ||||
-rw-r--r-- | test/core/transport/chttp2/alpn_test.c | 4 | ||||
-rw-r--r-- | test/cpp/end2end/end2end_test.cc | 29 | ||||
-rw-r--r-- | test/cpp/end2end/generic_end2end_test.cc | 9 | ||||
-rw-r--r-- | test/cpp/util/messages.proto | 2 |
6 files changed, 67 insertions, 16 deletions
diff --git a/test/core/end2end/tests/channel_connectivity.c b/test/core/end2end/tests/channel_connectivity.c index 3917cad4a7..ec0417abda 100644 --- a/test/core/end2end/tests/channel_connectivity.c +++ b/test/core/end2end/tests/channel_connectivity.c @@ -54,7 +54,7 @@ static void test_connectivity(grpc_end2end_test_config config) { /* start watching for a change */ grpc_channel_watch_connectivity_state( - f.client, GRPC_CHANNEL_IDLE, &state, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(3), f.cq, tag(1)); + f.client, GRPC_CHANNEL_IDLE, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(3), f.cq, tag(1)); /* nothing should happen */ cq_verify_empty(cqv); @@ -64,14 +64,18 @@ static void test_connectivity(grpc_end2end_test_config config) { /* and now the watch should trigger */ cq_expect_completion(cqv, tag(1), 1); cq_verify(cqv); - GPR_ASSERT(state == GRPC_CHANNEL_CONNECTING); + state = grpc_channel_check_connectivity_state(f.client, 0); + GPR_ASSERT(state == GRPC_CHANNEL_TRANSIENT_FAILURE || + state == GRPC_CHANNEL_CONNECTING); /* quickly followed by a transition to TRANSIENT_FAILURE */ grpc_channel_watch_connectivity_state( - f.client, GRPC_CHANNEL_CONNECTING, &state, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(3), f.cq, tag(2)); + f.client, GRPC_CHANNEL_CONNECTING, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(3), f.cq, tag(2)); cq_expect_completion(cqv, tag(2), 1); cq_verify(cqv); - GPR_ASSERT(state == GRPC_CHANNEL_TRANSIENT_FAILURE); + state = grpc_channel_check_connectivity_state(f.client, 0); + GPR_ASSERT(state == GRPC_CHANNEL_TRANSIENT_FAILURE || + state == GRPC_CHANNEL_CONNECTING); gpr_log(GPR_DEBUG, "*** STARTING SERVER ***"); @@ -84,10 +88,13 @@ static void test_connectivity(grpc_end2end_test_config config) { READY is reached */ while (state != GRPC_CHANNEL_READY) { grpc_channel_watch_connectivity_state( - f.client, state, &state, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(3), f.cq, tag(3)); + f.client, state, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(3), f.cq, tag(3)); cq_expect_completion(cqv, tag(3), 1); cq_verify(cqv); - GPR_ASSERT(state == GRPC_CHANNEL_READY || state == GRPC_CHANNEL_CONNECTING || state == GRPC_CHANNEL_TRANSIENT_FAILURE); + state = grpc_channel_check_connectivity_state(f.client, 0); + GPR_ASSERT(state == GRPC_CHANNEL_READY || + state == GRPC_CHANNEL_CONNECTING || + state == GRPC_CHANNEL_TRANSIENT_FAILURE); } /* bring down the server again */ @@ -95,14 +102,16 @@ static void test_connectivity(grpc_end2end_test_config config) { gpr_log(GPR_DEBUG, "*** SHUTTING DOWN SERVER ***"); grpc_channel_watch_connectivity_state( - f.client, GRPC_CHANNEL_READY, &state, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(3), f.cq, tag(4)); + f.client, GRPC_CHANNEL_READY, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(3), f.cq, tag(4)); grpc_server_shutdown_and_notify(f.server, f.cq, tag(0xdead)); cq_expect_completion(cqv, tag(4), 1); cq_expect_completion(cqv, tag(0xdead), 1); cq_verify(cqv); - GPR_ASSERT(state == GRPC_CHANNEL_TRANSIENT_FAILURE); + state = grpc_channel_check_connectivity_state(f.client, 0); + GPR_ASSERT(state == GRPC_CHANNEL_TRANSIENT_FAILURE || + state == GRPC_CHANNEL_CONNECTING); /* cleanup server */ grpc_server_destroy(f.server); diff --git a/test/core/iomgr/sockaddr_utils_test.c b/test/core/iomgr/sockaddr_utils_test.c index dfab340959..72a0f71835 100644 --- a/test/core/iomgr/sockaddr_utils_test.c +++ b/test/core/iomgr/sockaddr_utils_test.c @@ -187,6 +187,15 @@ static void expect_sockaddr_str(const char *expected, void *addr, gpr_free(str); } +static void expect_sockaddr_uri(const char *expected, void *addr) { + char *str; + gpr_log(GPR_INFO, " expect_sockaddr_uri(%s)", expected); + str = grpc_sockaddr_to_uri((struct sockaddr *)addr); + GPR_ASSERT(str != NULL); + GPR_ASSERT(strcmp(expected, str) == 0); + gpr_free(str); +} + static void test_sockaddr_to_string(void) { struct sockaddr_in input4; struct sockaddr_in6 input6; @@ -199,23 +208,28 @@ static void test_sockaddr_to_string(void) { input4 = make_addr4(kIPv4, sizeof(kIPv4)); expect_sockaddr_str("192.0.2.1:12345", &input4, 0); expect_sockaddr_str("192.0.2.1:12345", &input4, 1); + expect_sockaddr_uri("ipv4:192.0.2.1:12345", &input4); input6 = make_addr6(kIPv6, sizeof(kIPv6)); expect_sockaddr_str("[2001:db8::1]:12345", &input6, 0); expect_sockaddr_str("[2001:db8::1]:12345", &input6, 1); + expect_sockaddr_uri("ipv6:[2001:db8::1]:12345", &input6); input6 = make_addr6(kMapped, sizeof(kMapped)); expect_sockaddr_str("[::ffff:192.0.2.1]:12345", &input6, 0); expect_sockaddr_str("192.0.2.1:12345", &input6, 1); + expect_sockaddr_uri("ipv4:192.0.2.1:12345", &input6); input6 = make_addr6(kNotQuiteMapped, sizeof(kNotQuiteMapped)); expect_sockaddr_str("[::fffe:c000:263]:12345", &input6, 0); expect_sockaddr_str("[::fffe:c000:263]:12345", &input6, 1); + expect_sockaddr_uri("ipv6:[::fffe:c000:263]:12345", &input6); memset(&dummy, 0, sizeof(dummy)); dummy.sa_family = 123; expect_sockaddr_str("(sockaddr family=123)", &dummy, 0); expect_sockaddr_str("(sockaddr family=123)", &dummy, 1); + GPR_ASSERT(grpc_sockaddr_to_uri(&dummy) == NULL); GPR_ASSERT(errno == 0x7EADBEEF); } diff --git a/test/core/transport/chttp2/alpn_test.c b/test/core/transport/chttp2/alpn_test.c index c2497d3b1a..9a7d5ef0c3 100644 --- a/test/core/transport/chttp2/alpn_test.c +++ b/test/core/transport/chttp2/alpn_test.c @@ -37,9 +37,7 @@ #include "test/core/util/test_config.h" static void test_alpn_success(void) { - GPR_ASSERT(grpc_chttp2_is_alpn_version_supported("h2-16", 5)); - GPR_ASSERT(grpc_chttp2_is_alpn_version_supported("h2-15", 5)); - GPR_ASSERT(grpc_chttp2_is_alpn_version_supported("h2-14", 5)); + GPR_ASSERT(grpc_chttp2_is_alpn_version_supported("h2", 2)); } static void test_alpn_failure(void) { diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 5b351c169e..f39c6cf82a 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -93,6 +93,15 @@ void CheckServerAuthContext(const ServerContext* context) { EXPECT_TRUE(auth_ctx->GetPeerIdentity().empty()); } +bool CheckIsLocalhost(const grpc::string& addr) { + const grpc::string kIpv6("ipv6:[::1]:"); + const grpc::string kIpv4MappedIpv6("ipv6:[::ffff:127.0.0.1]:"); + const grpc::string kIpv4("ipv4:127.0.0.1:"); + return addr.substr(0, kIpv4.size()) == kIpv4 || + addr.substr(0, kIpv4MappedIpv6.size()) == kIpv4MappedIpv6 || + addr.substr(0, kIpv6.size()) == kIpv6; +} + } // namespace class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service { @@ -148,6 +157,9 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service { response->set_message( grpc::string(request->param().response_message_length(), '\0')); } + if (request->has_param() && request->param().echo_peer()) { + response->mutable_param()->set_peer(context->peer()); + } return Status::OK; } @@ -236,7 +248,7 @@ class End2endTest : public ::testing::Test { void SetUp() GRPC_OVERRIDE { int port = grpc_pick_unused_port_or_die(); - server_address_ << "localhost:" << port; + server_address_ << "127.0.0.1:" << port; // Setup server ServerBuilder builder; SslServerCredentialsOptions::PemKeyCertPair pkcp = {test_server1_key, @@ -818,6 +830,21 @@ TEST_F(End2endTest, HugeResponse) { EXPECT_TRUE(s.ok()); } +TEST_F(End2endTest, Peer) { + ResetStub(); + EchoRequest request; + EchoResponse response; + request.set_message("hello"); + request.mutable_param()->set_echo_peer(true); + + ClientContext context; + Status s = stub_->Echo(&context, request, &response); + EXPECT_EQ(response.message(), request.message()); + EXPECT_TRUE(s.ok()); + EXPECT_TRUE(CheckIsLocalhost(response.param().peer())); + EXPECT_TRUE(CheckIsLocalhost(context.peer())); +} + } // namespace testing } // namespace grpc diff --git a/test/cpp/end2end/generic_end2end_test.cc b/test/cpp/end2end/generic_end2end_test.cc index 4951c82b9a..b53c32144b 100644 --- a/test/cpp/end2end/generic_end2end_test.cc +++ b/test/cpp/end2end/generic_end2end_test.cc @@ -100,11 +100,11 @@ std::unique_ptr<ByteBuffer> SerializeToByteBuffer( class GenericEnd2endTest : public ::testing::Test { protected: - GenericEnd2endTest() : generic_service_("*") {} + GenericEnd2endTest() : generic_service_("*"), server_host_("localhost") {} void SetUp() GRPC_OVERRIDE { int port = grpc_pick_unused_port_or_die(); - server_address_ << "localhost:" << port; + server_address_ << server_host_ << ":" << port; // Setup server ServerBuilder builder; builder.AddListeningPort(server_address_.str(), InsecureServerCredentials()); @@ -165,7 +165,7 @@ class GenericEnd2endTest : public ::testing::Test { srv_cq_.get(), tag(4)); verify_ok(srv_cq_.get(), 4, true); - EXPECT_EQ(server_address_.str(), srv_ctx.host()); + EXPECT_EQ(server_host_, srv_ctx.host()); EXPECT_EQ(kMethodName, srv_ctx.method()); ByteBuffer recv_buffer; stream.Read(&recv_buffer, tag(5)); @@ -200,6 +200,7 @@ class GenericEnd2endTest : public ::testing::Test { std::unique_ptr<grpc::GenericStub> generic_stub_; std::unique_ptr<Server> server_; AsyncGenericService generic_service_; + const grpc::string server_host_; std::ostringstream server_address_; }; @@ -237,7 +238,7 @@ TEST_F(GenericEnd2endTest, SimpleBidiStreaming) { srv_cq_.get(), tag(2)); verify_ok(srv_cq_.get(), 2, true); - EXPECT_EQ(server_address_.str(), srv_ctx.host()); + EXPECT_EQ(server_host_, srv_ctx.host()); EXPECT_EQ(kMethodName, srv_ctx.method()); std::unique_ptr<ByteBuffer> send_buffer = diff --git a/test/cpp/util/messages.proto b/test/cpp/util/messages.proto index 2fad8b42a2..24e199b809 100644 --- a/test/cpp/util/messages.proto +++ b/test/cpp/util/messages.proto @@ -39,6 +39,7 @@ message RequestParams { optional bool echo_metadata = 4; optional bool check_auth_context = 5; optional int32 response_message_length = 6; + optional bool echo_peer = 7; } message EchoRequest { @@ -49,6 +50,7 @@ message EchoRequest { message ResponseParams { optional int64 request_deadline = 1; optional string host = 2; + optional string peer = 3; } message EchoResponse { |