aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar Julien Boeuf <jboeuf@google.com>2015-08-03 15:44:09 -0700
committerGravatar Julien Boeuf <jboeuf@google.com>2015-08-03 15:44:09 -0700
commit095f4f955957005969981e365bed12ae35f58acf (patch)
tree16ddc348a6bd217d7ee2aa8def1e23e2878f780f /test
parent0945420b348176fa176f2fd544e430ecedaa182c (diff)
parentbdd3c90ffaff4d80f06336eef4844ac188d4c623 (diff)
Merge branch 'master' of github.com:grpc/grpc into auth_md_processor
Diffstat (limited to 'test')
-rwxr-xr-xtest/core/end2end/gen_build_json.py30
-rw-r--r--test/core/end2end/tests/channel_connectivity.c25
-rw-r--r--test/core/end2end/tests/default_host.c220
-rw-r--r--test/core/transport/chttp2/alpn_test.c4
-rw-r--r--test/cpp/end2end/end2end_test.cc29
-rw-r--r--test/cpp/util/messages.proto2
6 files changed, 285 insertions, 25 deletions
diff --git a/test/core/end2end/gen_build_json.py b/test/core/end2end/gen_build_json.py
index d66442545f..43ab09f57d 100755
--- a/test/core/end2end/gen_build_json.py
+++ b/test/core/end2end/gen_build_json.py
@@ -36,30 +36,30 @@ import simplejson
import collections
-FixtureOptions = collections.namedtuple('FixtureOptions', 'fullstack secure platforms')
-default_unsecure_fixture_options = FixtureOptions(True, False, ['windows', 'posix'])
-socketpair_unsecure_fixture_options = FixtureOptions(False, False, ['windows', 'posix'])
-default_secure_fixture_options = FixtureOptions(True, True, ['windows', 'posix'])
+FixtureOptions = collections.namedtuple('FixtureOptions', 'fullstack dns_resolver secure platforms')
+default_unsecure_fixture_options = FixtureOptions(True, True, False, ['windows', 'posix'])
+socketpair_unsecure_fixture_options = FixtureOptions(False, False, False, ['windows', 'posix'])
+default_secure_fixture_options = FixtureOptions(True, True, True, ['windows', 'posix'])
# maps fixture name to whether it requires the security library
END2END_FIXTURES = {
'chttp2_fake_security': default_secure_fixture_options,
'chttp2_fullstack_compression': default_unsecure_fixture_options,
'chttp2_fullstack': default_unsecure_fixture_options,
- 'chttp2_fullstack_uds_posix': FixtureOptions(True, False, ['posix']),
- 'chttp2_fullstack_uds_posix_with_poll': FixtureOptions(True, False, ['posix']),
- 'chttp2_fullstack_with_poll': FixtureOptions(True, False, ['posix']),
+ 'chttp2_fullstack_uds_posix': FixtureOptions(True, False, False, ['posix']),
+ 'chttp2_fullstack_uds_posix_with_poll': FixtureOptions(True, False, False, ['posix']),
+ 'chttp2_fullstack_with_poll': FixtureOptions(True, True, False, ['posix']),
'chttp2_simple_ssl_fullstack': default_secure_fixture_options,
- 'chttp2_simple_ssl_fullstack_with_poll': FixtureOptions(True, True, ['posix']),
+ 'chttp2_simple_ssl_fullstack_with_poll': FixtureOptions(True, True, True, ['posix']),
'chttp2_simple_ssl_with_oauth2_fullstack': default_secure_fixture_options,
'chttp2_socket_pair_one_byte_at_a_time': socketpair_unsecure_fixture_options,
'chttp2_socket_pair': socketpair_unsecure_fixture_options,
'chttp2_socket_pair_with_grpc_trace': socketpair_unsecure_fixture_options,
}
-TestOptions = collections.namedtuple('TestOptions', 'needs_fullstack flaky secure')
-default_test_options = TestOptions(False, False, False)
-connectivity_test_options = TestOptions(True, False, False)
+TestOptions = collections.namedtuple('TestOptions', 'needs_fullstack needs_dns flaky secure')
+default_test_options = TestOptions(False, False, False, False)
+connectivity_test_options = TestOptions(True, False, False, False)
# maps test names to options
END2END_TESTS = {
@@ -71,6 +71,7 @@ END2END_TESTS = {
'cancel_in_a_vacuum': default_test_options,
'census_simple_request': default_test_options,
'channel_connectivity': connectivity_test_options,
+ 'default_host': TestOptions(True, True, False, False),
'disappearing_server': connectivity_test_options,
'early_server_shutdown_finishes_inflight_calls': default_test_options,
'early_server_shutdown_finishes_tags': default_test_options,
@@ -84,7 +85,7 @@ END2END_TESTS = {
'registered_call': default_test_options,
'request_response_with_binary_metadata_and_payload': default_test_options,
'request_response_with_metadata_and_payload': default_test_options,
- 'request_response_with_payload_and_call_creds': TestOptions(needs_fullstack=False, flaky=False, secure=True),
+ 'request_response_with_payload_and_call_creds': TestOptions(needs_fullstack=False, needs_dns=False, flaky=False, secure=True),
'request_response_with_payload': default_test_options,
'request_response_with_trailing_metadata_and_payload': default_test_options,
'request_with_compressed_payload': default_test_options,
@@ -102,6 +103,9 @@ def compatible(f, t):
if END2END_TESTS[t].needs_fullstack:
if not END2END_FIXTURES[f].fullstack:
return False
+ if END2END_TESTS[t].needs_dns:
+ if not END2END_FIXTURES[f].dns_resolver:
+ return False
return True
@@ -176,7 +180,7 @@ def main():
'language': 'c',
'secure': 'no',
'src': [],
- 'flaky': 'invoke_large_request' in t,
+ 'flaky': END2END_TESTS[t].flaky,
'platforms': END2END_FIXTURES[f].platforms,
'deps': [
'end2end_fixture_%s' % f,
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/end2end/tests/default_host.c b/test/core/end2end/tests/default_host.c
new file mode 100644
index 0000000000..63ef4bcd35
--- /dev/null
+++ b/test/core/end2end/tests/default_host.c
@@ -0,0 +1,220 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <stdio.h>
+#include <string.h>
+
+#include "src/core/support/string.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 <grpc/support/useful.h>
+#include "test/core/end2end/cq_verifier.h"
+
+enum { TIMEOUT = 200000 };
+
+static void *tag(gpr_intptr 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, "%s/%s", test_name, config.name);
+ f = config.create_fixture(client_args, server_args);
+ config.init_client(&f, client_args);
+ config.init_server(&f, server_args);
+ return f;
+}
+
+static gpr_timespec n_seconds_time(int n) {
+ return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(n);
+}
+
+static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
+
+static void drain_cq(grpc_completion_queue *cq) {
+ grpc_event ev;
+ do {
+ ev = grpc_completion_queue_next(cq, five_seconds_time());
+ } 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->cq, tag(1000));
+ GPR_ASSERT(grpc_completion_queue_pluck(f->cq, tag(1000),
+ GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5))
+ .type == GRPC_OP_COMPLETE);
+ grpc_server_destroy(f->server);
+ f->server = NULL;
+}
+
+static void shutdown_client(grpc_end2end_test_fixture *f) {
+ if (!f->client) return;
+ grpc_channel_destroy(f->client);
+ f->client = NULL;
+}
+
+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);
+}
+
+static void simple_request_body(grpc_end2end_test_fixture f) {
+ grpc_call *c;
+ grpc_call *s;
+ gpr_timespec deadline = five_seconds_time();
+ 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;
+ char *details = NULL;
+ size_t details_capacity = 0;
+ int was_cancelled = 2;
+ char *peer;
+
+ c = grpc_channel_create_call(f.client, f.cq, "/foo", NULL, deadline);
+ GPR_ASSERT(c);
+
+ peer = grpc_call_get_peer(c);
+ GPR_ASSERT(peer != NULL);
+ gpr_log(GPR_DEBUG, "client_peer_before_call=%s", peer);
+ gpr_free(peer);
+
+ 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);
+
+ op = ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 0;
+ op->flags = 0;
+ op++;
+ op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
+ op->flags = 0;
+ op++;
+ op->op = GRPC_OP_RECV_INITIAL_METADATA;
+ op->data.recv_initial_metadata = &initial_metadata_recv;
+ op->flags = 0;
+ 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.status_details_capacity = &details_capacity;
+ op->flags = 0;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(c, ops, op - ops, tag(1)));
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(
+ f.server, &s, &call_details,
+ &request_metadata_recv, f.cq, f.cq, tag(101)));
+ cq_expect_completion(cqv, tag(101), 1);
+ cq_verify(cqv);
+
+ peer = grpc_call_get_peer(s);
+ GPR_ASSERT(peer != NULL);
+ gpr_log(GPR_DEBUG, "server_peer=%s", peer);
+ gpr_free(peer);
+ peer = grpc_call_get_peer(c);
+ GPR_ASSERT(peer != NULL);
+ gpr_log(GPR_DEBUG, "client_peer=%s", peer);
+ gpr_free(peer);
+
+ op = ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 0;
+ op->flags = 0;
+ 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_UNIMPLEMENTED;
+ op->data.send_status_from_server.status_details = "xyz";
+ op->flags = 0;
+ op++;
+ op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
+ op->data.recv_close_on_server.cancelled = &was_cancelled;
+ op->flags = 0;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(s, ops, op - ops, tag(102)));
+
+ cq_expect_completion(cqv, tag(102), 1);
+ cq_expect_completion(cqv, tag(1), 1);
+ cq_verify(cqv);
+
+ GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED);
+ GPR_ASSERT(0 == strcmp(details, "xyz"));
+ GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
+ GPR_ASSERT(0 == strcmp(call_details.host, "localhost"));
+ GPR_ASSERT(was_cancelled == 1);
+
+ gpr_free(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_destroy(c);
+ grpc_call_destroy(s);
+
+ cq_verifier_destroy(cqv);
+}
+
+static void test_invoke_simple_request(grpc_end2end_test_config config) {
+ grpc_end2end_test_fixture f;
+
+ f = begin_test(config, "test_invoke_simple_request", NULL, NULL);
+ simple_request_body(f);
+ end_test(&f);
+ config.tear_down_data(&f);
+}
+
+void grpc_end2end_tests(grpc_end2end_test_config config) {
+ if ((config.feature_mask & FEATURE_MASK_SUPPORTS_HOSTNAME_VERIFICATION) != 0) return;
+ if ((config.feature_mask & FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION) == 0) return;
+ test_invoke_simple_request(config);
+}
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/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 {