aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Makefile36
-rw-r--r--build.yaml15
-rw-r--r--src/core/lib/client_config/uri_parser.c68
-rw-r--r--src/core/lib/client_config/uri_parser.h12
-rw-r--r--src/python/grpcio/grpc/beta/implementations.py11
-rw-r--r--src/python/grpcio/tests/interop/_secure_interop_test.py4
-rw-r--r--src/python/grpcio/tests/interop/client.py4
-rw-r--r--src/python/grpcio/tests/unit/beta/_beta_features_test.py6
-rw-r--r--src/python/grpcio/tests/unit/beta/_face_interface_test.py4
-rw-r--r--src/python/grpcio/tests/unit/beta/_implementations_test.py5
-rw-r--r--test/core/client_config/uri_parser_test.c51
-rw-r--r--test/core/end2end/goaway_server_test.c301
-rw-r--r--test/cpp/end2end/thread_stress_test.cc1
-rw-r--r--tools/run_tests/sources_and_headers.json16
-rw-r--r--tools/run_tests/stress_test/STRESS_CLIENT_SPEC.md2
-rw-r--r--tools/run_tests/tests.json19
16 files changed, 537 insertions, 18 deletions
diff --git a/Makefile b/Makefile
index e9ae6f3072..01fd08740e 100644
--- a/Makefile
+++ b/Makefile
@@ -902,6 +902,7 @@ fling_stream_test: $(BINDIR)/$(CONFIG)/fling_stream_test
fling_test: $(BINDIR)/$(CONFIG)/fling_test
gen_hpack_tables: $(BINDIR)/$(CONFIG)/gen_hpack_tables
gen_legal_metadata_characters: $(BINDIR)/$(CONFIG)/gen_legal_metadata_characters
+goaway_server_test: $(BINDIR)/$(CONFIG)/goaway_server_test
gpr_avl_test: $(BINDIR)/$(CONFIG)/gpr_avl_test
gpr_backoff_test: $(BINDIR)/$(CONFIG)/gpr_backoff_test
gpr_cmdline_test: $(BINDIR)/$(CONFIG)/gpr_cmdline_test
@@ -1222,6 +1223,7 @@ buildtests_c: privatelibs_c \
$(BINDIR)/$(CONFIG)/fling_server \
$(BINDIR)/$(CONFIG)/fling_stream_test \
$(BINDIR)/$(CONFIG)/fling_test \
+ $(BINDIR)/$(CONFIG)/goaway_server_test \
$(BINDIR)/$(CONFIG)/gpr_avl_test \
$(BINDIR)/$(CONFIG)/gpr_backoff_test \
$(BINDIR)/$(CONFIG)/gpr_cmdline_test \
@@ -1480,6 +1482,8 @@ test_c: buildtests_c
$(Q) $(BINDIR)/$(CONFIG)/fling_stream_test || ( echo test fling_stream_test failed ; exit 1 )
$(E) "[RUN] Testing fling_test"
$(Q) $(BINDIR)/$(CONFIG)/fling_test || ( echo test fling_test failed ; exit 1 )
+ $(E) "[RUN] Testing goaway_server_test"
+ $(Q) $(BINDIR)/$(CONFIG)/goaway_server_test || ( echo test goaway_server_test failed ; exit 1 )
$(E) "[RUN] Testing gpr_avl_test"
$(Q) $(BINDIR)/$(CONFIG)/gpr_avl_test || ( echo test gpr_avl_test failed ; exit 1 )
$(E) "[RUN] Testing gpr_backoff_test"
@@ -6754,6 +6758,38 @@ endif
endif
+GOAWAY_SERVER_TEST_SRC = \
+ test/core/end2end/goaway_server_test.c \
+
+GOAWAY_SERVER_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(GOAWAY_SERVER_TEST_SRC))))
+ifeq ($(NO_SECURE),true)
+
+# You can't build secure targets if you don't have OpenSSL.
+
+$(BINDIR)/$(CONFIG)/goaway_server_test: openssl_dep_error
+
+else
+
+
+
+$(BINDIR)/$(CONFIG)/goaway_server_test: $(GOAWAY_SERVER_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
+ $(E) "[LD] Linking $@"
+ $(Q) mkdir -p `dirname $@`
+ $(Q) $(LD) $(LDFLAGS) $(GOAWAY_SERVER_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/goaway_server_test
+
+endif
+
+$(OBJDIR)/$(CONFIG)/test/core/end2end/goaway_server_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
+
+deps_goaway_server_test: $(GOAWAY_SERVER_TEST_OBJS:.o=.dep)
+
+ifneq ($(NO_SECURE),true)
+ifneq ($(NO_DEPS),true)
+-include $(GOAWAY_SERVER_TEST_OBJS:.o=.dep)
+endif
+endif
+
+
GPR_AVL_TEST_SRC = \
test/core/support/avl_test.c \
diff --git a/build.yaml b/build.yaml
index c5f2ff5d45..c4b1c33fd5 100644
--- a/build.yaml
+++ b/build.yaml
@@ -1294,6 +1294,21 @@ targets:
src:
- tools/codegen/core/gen_legal_metadata_characters.c
deps: []
+- name: goaway_server_test
+ cpu_cost: 0.1
+ build: test
+ language: c
+ src:
+ - test/core/end2end/goaway_server_test.c
+ deps:
+ - grpc_test_util
+ - grpc
+ - gpr_test_util
+ - gpr
+ platforms:
+ - mac
+ - linux
+ - posix
- name: gpr_avl_test
build: test
language: c
diff --git a/src/core/lib/client_config/uri_parser.c b/src/core/lib/client_config/uri_parser.c
index b4ee763735..6bec70da2d 100644
--- a/src/core/lib/client_config/uri_parser.c
+++ b/src/core/lib/client_config/uri_parser.c
@@ -38,8 +38,12 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
+#include <grpc/support/slice.h>
+#include <grpc/support/slice_buffer.h>
#include <grpc/support/string_util.h>
+#include "src/core/lib/support/string.h"
+
/** a size_t default value... maps to all 1's */
#define NOT_SET (~(size_t)0)
@@ -133,6 +137,51 @@ static int parse_fragment_or_query(const char *uri_text, size_t *i) {
return 1;
}
+static void do_nothing(void *ignored) {}
+static void parse_query_parts(grpc_uri *uri) {
+ static const char *QUERY_PARTS_SEPARATOR = "&";
+ static const char *QUERY_PARTS_VALUE_SEPARATOR = "=";
+ GPR_ASSERT(uri->query != NULL);
+ if (uri->query[0] == '\0') {
+ uri->query_parts = NULL;
+ uri->query_parts_values = NULL;
+ uri->num_query_parts = 0;
+ return;
+ }
+ gpr_slice query_slice =
+ gpr_slice_new(uri->query, strlen(uri->query), do_nothing);
+ gpr_slice_buffer query_parts; /* the &-separated elements of the query */
+ gpr_slice_buffer query_param_parts; /* the =-separated subelements */
+
+ gpr_slice_buffer_init(&query_parts);
+ gpr_slice_buffer_init(&query_param_parts);
+
+ gpr_slice_split(query_slice, QUERY_PARTS_SEPARATOR, &query_parts);
+ uri->query_parts = gpr_malloc(query_parts.count * sizeof(char *));
+ uri->query_parts_values = gpr_malloc(query_parts.count * sizeof(char *));
+ uri->num_query_parts = query_parts.count;
+ for (size_t i = 0; i < query_parts.count; i++) {
+ gpr_slice_split(query_parts.slices[i], QUERY_PARTS_VALUE_SEPARATOR,
+ &query_param_parts);
+ GPR_ASSERT(query_param_parts.count > 0);
+ uri->query_parts[i] =
+ gpr_dump_slice(query_param_parts.slices[0], GPR_DUMP_ASCII);
+ if (query_param_parts.count > 1) {
+ /* TODO(dgq): only the first value after the separator is considered.
+ * Perhaps all chars after the first separator for the query part should
+ * be included, even if they include the separator. */
+ uri->query_parts_values[i] =
+ gpr_dump_slice(query_param_parts.slices[1], GPR_DUMP_ASCII);
+ } else {
+ uri->query_parts_values[i] = NULL;
+ }
+ gpr_slice_buffer_reset_and_unref(&query_param_parts);
+ }
+ gpr_slice_buffer_destroy(&query_parts);
+ gpr_slice_buffer_destroy(&query_param_parts);
+ gpr_slice_unref(query_slice);
+}
+
grpc_uri *grpc_uri_parse(const char *uri_text, int suppress_errors) {
grpc_uri *uri;
size_t scheme_begin = 0;
@@ -227,16 +276,35 @@ grpc_uri *grpc_uri_parse(const char *uri_text, int suppress_errors) {
uri->path = copy_component(uri_text, path_begin, path_end);
uri->query = copy_component(uri_text, query_begin, query_end);
uri->fragment = copy_component(uri_text, fragment_begin, fragment_end);
+ parse_query_parts(uri);
return uri;
}
+const char *grpc_uri_get_query_arg(const grpc_uri *uri, const char *key) {
+ GPR_ASSERT(key != NULL);
+ if (key[0] == '\0') return NULL;
+
+ for (size_t i = 0; i < uri->num_query_parts; ++i) {
+ if (0 == strcmp(key, uri->query_parts[i])) {
+ return uri->query_parts_values[i];
+ }
+ }
+ return NULL;
+}
+
void grpc_uri_destroy(grpc_uri *uri) {
if (!uri) return;
gpr_free(uri->scheme);
gpr_free(uri->authority);
gpr_free(uri->path);
gpr_free(uri->query);
+ for (size_t i = 0; i < uri->num_query_parts; ++i) {
+ gpr_free(uri->query_parts[i]);
+ gpr_free(uri->query_parts_values[i]);
+ }
+ gpr_free(uri->query_parts);
+ gpr_free(uri->query_parts_values);
gpr_free(uri->fragment);
gpr_free(uri);
}
diff --git a/src/core/lib/client_config/uri_parser.h b/src/core/lib/client_config/uri_parser.h
index 4f8e809b2e..5d6785d293 100644
--- a/src/core/lib/client_config/uri_parser.h
+++ b/src/core/lib/client_config/uri_parser.h
@@ -34,17 +34,29 @@
#ifndef GRPC_CORE_LIB_CLIENT_CONFIG_URI_PARSER_H
#define GRPC_CORE_LIB_CLIENT_CONFIG_URI_PARSER_H
+#include <stddef.h>
+
typedef struct {
char *scheme;
char *authority;
char *path;
char *query;
+ /** Query substrings separated by '&' */
+ char **query_parts;
+ /** Number of elements in \a query_parts and \a query_parts_values */
+ size_t num_query_parts;
+ /** Split each query part by '='. NULL if not present. */
+ char **query_parts_values;
char *fragment;
} grpc_uri;
/** parse a uri, return NULL on failure */
grpc_uri *grpc_uri_parse(const char *uri_text, int suppress_errors);
+/** return the part of a query string after the '=' in "?key=xxx&...", or NULL
+ * if key is not present */
+const char *grpc_uri_get_query_arg(const grpc_uri *uri, const char *key);
+
/** destroy a uri */
void grpc_uri_destroy(grpc_uri *uri);
diff --git a/src/python/grpcio/grpc/beta/implementations.py b/src/python/grpcio/grpc/beta/implementations.py
index a0ca330d2c..06ee7aa26e 100644
--- a/src/python/grpcio/grpc/beta/implementations.py
+++ b/src/python/grpcio/grpc/beta/implementations.py
@@ -1,4 +1,4 @@
-# Copyright 2015, Google Inc.
+# Copyright 2015-2016, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -61,15 +61,16 @@ class ChannelCredentials(object):
self._low_credentials = low_credentials
-def ssl_channel_credentials(root_certificates, private_key, certificate_chain):
+def ssl_channel_credentials(root_certificates=None, private_key=None,
+ certificate_chain=None):
"""Creates a ChannelCredentials for use with an SSL-enabled Channel.
Args:
- root_certificates: The PEM-encoded root certificates or None to ask for
+ root_certificates: The PEM-encoded root certificates or unset to ask for
them to be retrieved from a default location.
- private_key: The PEM-encoded private key to use or None if no private key
+ private_key: The PEM-encoded private key to use or unset if no private key
should be used.
- certificate_chain: The PEM-encoded certificate chain to use or None if no
+ certificate_chain: The PEM-encoded certificate chain to use or unset if no
certificate chain should be used.
Returns:
diff --git a/src/python/grpcio/tests/interop/_secure_interop_test.py b/src/python/grpcio/tests/interop/_secure_interop_test.py
index 7e3061133f..1a1a063a6f 100644
--- a/src/python/grpcio/tests/interop/_secure_interop_test.py
+++ b/src/python/grpcio/tests/interop/_secure_interop_test.py
@@ -1,4 +1,4 @@
-# Copyright 2015, Google Inc.
+# Copyright 2015-2016, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -56,7 +56,7 @@ class SecureInteropTest(
self.stub = test_pb2.beta_create_TestService_stub(
test_utilities.not_really_secure_channel(
'[::]', port, implementations.ssl_channel_credentials(
- resources.test_root_certificates(), None, None),
+ resources.test_root_certificates()),
_SERVER_HOST_OVERRIDE))
def tearDown(self):
diff --git a/src/python/grpcio/tests/interop/client.py b/src/python/grpcio/tests/interop/client.py
index 573ec2bd71..02a37cc6bc 100644
--- a/src/python/grpcio/tests/interop/client.py
+++ b/src/python/grpcio/tests/interop/client.py
@@ -1,4 +1,4 @@
-# Copyright 2015, Google Inc.
+# Copyright 2015-2016, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -94,7 +94,7 @@ def _stub(args):
channel = test_utilities.not_really_secure_channel(
args.server_host, args.server_port,
- implementations.ssl_channel_credentials(root_certificates, None, None),
+ implementations.ssl_channel_credentials(root_certificates),
args.server_host_override)
stub = test_pb2.beta_create_TestService_stub(
channel, metadata_transformer=metadata_transformer)
diff --git a/src/python/grpcio/tests/unit/beta/_beta_features_test.py b/src/python/grpcio/tests/unit/beta/_beta_features_test.py
index 10877cd310..b8b77a96c1 100644
--- a/src/python/grpcio/tests/unit/beta/_beta_features_test.py
+++ b/src/python/grpcio/tests/unit/beta/_beta_features_test.py
@@ -1,4 +1,4 @@
-# Copyright 2015, Google Inc.
+# Copyright 2015-2016, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -183,7 +183,7 @@ class BetaFeaturesTest(unittest.TestCase):
port = self._server.add_secure_port('[::]:0', server_credentials)
self._server.start()
self._channel_credentials = implementations.ssl_channel_credentials(
- resources.test_root_certificates(), None, None)
+ resources.test_root_certificates())
self._call_credentials = implementations.metadata_call_credentials(
_metadata_plugin)
channel = test_utilities.not_really_secure_channel(
@@ -296,7 +296,7 @@ class ContextManagementAndLifecycleTest(unittest.TestCase):
self._server_credentials = implementations.ssl_server_credentials(
[(resources.private_key(), resources.certificate_chain(),),])
self._channel_credentials = implementations.ssl_channel_credentials(
- resources.test_root_certificates(), None, None)
+ resources.test_root_certificates())
self._stub_options = implementations.stub_options(
thread_pool_size=test_constants.POOL_SIZE)
diff --git a/src/python/grpcio/tests/unit/beta/_face_interface_test.py b/src/python/grpcio/tests/unit/beta/_face_interface_test.py
index ef01908c3b..ea19ee47ae 100644
--- a/src/python/grpcio/tests/unit/beta/_face_interface_test.py
+++ b/src/python/grpcio/tests/unit/beta/_face_interface_test.py
@@ -1,4 +1,4 @@
-# Copyright 2015, Google Inc.
+# Copyright 2015-2016, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -94,7 +94,7 @@ class _Implementation(test_interfaces.Implementation):
port = server.add_secure_port('[::]:0', server_credentials)
server.start()
channel_credentials = implementations.ssl_channel_credentials(
- resources.test_root_certificates(), None, None)
+ resources.test_root_certificates())
channel = test_utilities.not_really_secure_channel(
'localhost', port, channel_credentials, _SERVER_HOST_OVERRIDE)
stub_options = implementations.stub_options(
diff --git a/src/python/grpcio/tests/unit/beta/_implementations_test.py b/src/python/grpcio/tests/unit/beta/_implementations_test.py
index 6b32305af7..26be670c45 100644
--- a/src/python/grpcio/tests/unit/beta/_implementations_test.py
+++ b/src/python/grpcio/tests/unit/beta/_implementations_test.py
@@ -38,14 +38,13 @@ from tests.unit import resources
class ChannelCredentialsTest(unittest.TestCase):
def test_runtime_provided_root_certificates(self):
- channel_credentials = implementations.ssl_channel_credentials(
- None, None, None)
+ channel_credentials = implementations.ssl_channel_credentials()
self.assertIsInstance(
channel_credentials, implementations.ChannelCredentials)
def test_application_provided_root_certificates(self):
channel_credentials = implementations.ssl_channel_credentials(
- resources.test_root_certificates(), None, None)
+ resources.test_root_certificates())
self.assertIsInstance(
channel_credentials, implementations.ChannelCredentials)
diff --git a/test/core/client_config/uri_parser_test.c b/test/core/client_config/uri_parser_test.c
index e5d0c378ba..37b82aeded 100644
--- a/test/core/client_config/uri_parser_test.c
+++ b/test/core/client_config/uri_parser_test.c
@@ -56,6 +56,56 @@ static void test_fails(const char *uri_text) {
GPR_ASSERT(NULL == grpc_uri_parse(uri_text, 0));
}
+static void test_query_parts() {
+ {
+ const char *uri_text = "http://foo/path?a&b=B&c=&#frag";
+ grpc_uri *uri = grpc_uri_parse(uri_text, 0);
+ GPR_ASSERT(uri);
+
+ GPR_ASSERT(0 == strcmp("http", uri->scheme));
+ GPR_ASSERT(0 == strcmp("foo", uri->authority));
+ GPR_ASSERT(0 == strcmp("/path", uri->path));
+ GPR_ASSERT(0 == strcmp("a&b=B&c=&", uri->query));
+ GPR_ASSERT(4 == uri->num_query_parts);
+
+ GPR_ASSERT(0 == strcmp("a", uri->query_parts[0]));
+ GPR_ASSERT(NULL == uri->query_parts_values[0]);
+
+ GPR_ASSERT(0 == strcmp("b", uri->query_parts[1]));
+ GPR_ASSERT(0 == strcmp("B", uri->query_parts_values[1]));
+
+ GPR_ASSERT(0 == strcmp("c", uri->query_parts[2]));
+ GPR_ASSERT(0 == strcmp("", uri->query_parts_values[2]));
+
+ GPR_ASSERT(0 == strcmp("", uri->query_parts[3]));
+ GPR_ASSERT(NULL == uri->query_parts_values[3]);
+
+ GPR_ASSERT(NULL == grpc_uri_get_query_arg(uri, "a"));
+ GPR_ASSERT(0 == strcmp("B", grpc_uri_get_query_arg(uri, "b")));
+ GPR_ASSERT(0 == strcmp("", grpc_uri_get_query_arg(uri, "c")));
+ GPR_ASSERT(NULL == grpc_uri_get_query_arg(uri, ""));
+
+ GPR_ASSERT(0 == strcmp("frag", uri->fragment));
+ grpc_uri_destroy(uri);
+ }
+ {
+ /* empty query */
+ const char *uri_text = "http://foo/path";
+ grpc_uri *uri = grpc_uri_parse(uri_text, 0);
+ GPR_ASSERT(uri);
+
+ GPR_ASSERT(0 == strcmp("http", uri->scheme));
+ GPR_ASSERT(0 == strcmp("foo", uri->authority));
+ GPR_ASSERT(0 == strcmp("/path", uri->path));
+ GPR_ASSERT(0 == strcmp("", uri->query));
+ GPR_ASSERT(0 == uri->num_query_parts);
+ GPR_ASSERT(NULL == uri->query_parts);
+ GPR_ASSERT(NULL == uri->query_parts_values);
+ GPR_ASSERT(0 == strcmp("", uri->fragment));
+ grpc_uri_destroy(uri);
+ }
+}
+
int main(int argc, char **argv) {
grpc_test_init(argc, argv);
test_succeeds("http://www.google.com", "http", "www.google.com", "", "", "");
@@ -82,5 +132,6 @@ int main(int argc, char **argv) {
test_fails("http://foo?x[bar]");
test_fails("http://foo?bar#lol#");
+ test_query_parts();
return 0;
}
diff --git a/test/core/end2end/goaway_server_test.c b/test/core/end2end/goaway_server_test.c
new file mode 100644
index 0000000000..5f8c2641e7
--- /dev/null
+++ b/test/core/end2end/goaway_server_test.c
@@ -0,0 +1,301 @@
+/*
+ *
+ * Copyright 2016, 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 <grpc/grpc.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/string_util.h>
+#include <string.h>
+#include "src/core/lib/iomgr/resolve_address.h"
+#include "src/core/lib/iomgr/sockaddr.h"
+#include "test/core/end2end/cq_verifier.h"
+#include "test/core/util/port.h"
+#include "test/core/util/test_config.h"
+
+static void *tag(intptr_t i) { return (void *)i; }
+
+static gpr_mu g_mu;
+static int g_resolve_port = -1;
+static grpc_resolved_addresses *(*iomgr_resolve_address)(
+ const char *name, const char *default_port);
+
+static void set_resolve_port(int port) {
+ gpr_mu_lock(&g_mu);
+ g_resolve_port = port;
+ gpr_mu_unlock(&g_mu);
+}
+
+static grpc_resolved_addresses *my_resolve_address(const char *name,
+ const char *addr) {
+ if (0 != strcmp(name, "test")) {
+ return iomgr_resolve_address(name, addr);
+ }
+
+ gpr_mu_lock(&g_mu);
+ if (g_resolve_port < 0) {
+ gpr_mu_unlock(&g_mu);
+ return NULL;
+ } else {
+ grpc_resolved_addresses *addrs = gpr_malloc(sizeof(*addrs));
+ addrs->naddrs = 1;
+ addrs->addrs = gpr_malloc(sizeof(*addrs->addrs));
+ memset(addrs->addrs, 0, sizeof(*addrs->addrs));
+ struct sockaddr_in *sa = (struct sockaddr_in *)addrs->addrs[0].addr;
+ sa->sin_family = AF_INET;
+ sa->sin_addr.s_addr = htonl(0x7f000001);
+ sa->sin_port = htons((uint16_t)g_resolve_port);
+ addrs->addrs[0].len = sizeof(*sa);
+ gpr_mu_unlock(&g_mu);
+ return addrs;
+ }
+}
+
+int main(int argc, char **argv) {
+ grpc_completion_queue *cq;
+ cq_verifier *cqv;
+ grpc_op ops[6];
+ grpc_op *op;
+
+ grpc_test_init(argc, argv);
+
+ gpr_mu_init(&g_mu);
+ iomgr_resolve_address = grpc_blocking_resolve_address;
+ grpc_blocking_resolve_address = my_resolve_address;
+ grpc_init();
+
+ int was_cancelled1;
+ int was_cancelled2;
+
+ grpc_metadata_array trailing_metadata_recv1;
+ grpc_metadata_array request_metadata1;
+ grpc_call_details request_details1;
+ grpc_status_code status1;
+ char *details1 = NULL;
+ size_t details_capacity1 = 0;
+ grpc_metadata_array_init(&trailing_metadata_recv1);
+ grpc_metadata_array_init(&request_metadata1);
+ grpc_call_details_init(&request_details1);
+
+ grpc_metadata_array trailing_metadata_recv2;
+ grpc_metadata_array request_metadata2;
+ grpc_call_details request_details2;
+ grpc_status_code status2;
+ char *details2 = NULL;
+ size_t details_capacity2 = 0;
+ grpc_metadata_array_init(&trailing_metadata_recv2);
+ grpc_metadata_array_init(&request_metadata2);
+ grpc_call_details_init(&request_details2);
+
+ cq = grpc_completion_queue_create(NULL);
+ cqv = cq_verifier_create(cq);
+
+ /* reserve two ports */
+ int port1 = grpc_pick_unused_port_or_die();
+ int port2 = grpc_pick_unused_port_or_die();
+
+ char *addr;
+
+ /* create a channel that picks first amongst the servers */
+ grpc_channel *chan = grpc_insecure_channel_create("test", NULL, NULL);
+ /* and an initial call to them */
+ grpc_call *call1 = grpc_channel_create_call(
+ chan, NULL, GRPC_PROPAGATE_DEFAULTS, cq, "/foo", "127.0.0.1",
+ GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20), NULL);
+ /* send initial metadata to probe connectivity */
+ op = ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 0;
+ op->flags = 0;
+ op->reserved = NULL;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(call1, ops,
+ (size_t)(op - ops),
+ tag(0x101), NULL));
+ /* and receive status to probe termination */
+ op = ops;
+ op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
+ op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv1;
+ op->data.recv_status_on_client.status = &status1;
+ op->data.recv_status_on_client.status_details = &details1;
+ op->data.recv_status_on_client.status_details_capacity = &details_capacity1;
+ op->flags = 0;
+ op->reserved = NULL;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(call1, ops,
+ (size_t)(op - ops),
+ tag(0x102), NULL));
+
+ /* bring a server up on the first port */
+ grpc_server *server1 = grpc_server_create(NULL, NULL);
+ gpr_asprintf(&addr, "127.0.0.1:%d", port1);
+ grpc_server_add_insecure_http2_port(server1, addr);
+ grpc_server_register_completion_queue(server1, cq, NULL);
+ gpr_free(addr);
+ grpc_server_start(server1);
+
+ /* request a call to the server */
+ grpc_call *server_call1;
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_server_request_call(server1, &server_call1, &request_details1,
+ &request_metadata1, cq, cq, tag(0x301)));
+
+ set_resolve_port(port1);
+
+ /* first call should now start */
+ cq_expect_completion(cqv, tag(0x101), 1);
+ cq_expect_completion(cqv, tag(0x301), 1);
+ cq_verify(cqv);
+
+ GPR_ASSERT(GRPC_CHANNEL_READY ==
+ grpc_channel_check_connectivity_state(chan, 0));
+ grpc_channel_watch_connectivity_state(chan, GRPC_CHANNEL_READY,
+ gpr_inf_future(GPR_CLOCK_REALTIME), cq,
+ tag(0x9999));
+
+ /* listen for close on the server call to probe for finishing */
+ op = ops;
+ op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
+ op->data.recv_close_on_server.cancelled = &was_cancelled1;
+ op->flags = 0;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(server_call1, ops,
+ (size_t)(op - ops),
+ tag(0x302), NULL));
+
+ /* shutdown first server:
+ * we should see a connectivity change and then nothing */
+ set_resolve_port(-1);
+ grpc_server_shutdown_and_notify(server1, cq, tag(0xdead1));
+ cq_expect_completion(cqv, tag(0x9999), 1);
+ cq_verify(cqv);
+ cq_verify_empty(cqv);
+
+ /* and a new call: should go through to server2 when we start it */
+ grpc_call *call2 = grpc_channel_create_call(
+ chan, NULL, GRPC_PROPAGATE_DEFAULTS, cq, "/foo", "127.0.0.1",
+ GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20), NULL);
+ /* send initial metadata to probe connectivity */
+ op = ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 0;
+ op->flags = 0;
+ op->reserved = NULL;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(call2, ops,
+ (size_t)(op - ops),
+ tag(0x201), NULL));
+ /* and receive status to probe termination */
+ op = ops;
+ op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
+ op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv2;
+ op->data.recv_status_on_client.status = &status2;
+ op->data.recv_status_on_client.status_details = &details2;
+ op->data.recv_status_on_client.status_details_capacity = &details_capacity2;
+ op->flags = 0;
+ op->reserved = NULL;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(call2, ops,
+ (size_t)(op - ops),
+ tag(0x202), NULL));
+
+ /* and bring up second server */
+ set_resolve_port(port2);
+ grpc_server *server2 = grpc_server_create(NULL, NULL);
+ gpr_asprintf(&addr, "127.0.0.1:%d", port2);
+ grpc_server_add_insecure_http2_port(server2, addr);
+ grpc_server_register_completion_queue(server2, cq, NULL);
+ gpr_free(addr);
+ grpc_server_start(server2);
+
+ /* request a call to the server */
+ grpc_call *server_call2;
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_server_request_call(server2, &server_call2, &request_details2,
+ &request_metadata2, cq, cq, tag(0x401)));
+
+ /* second call should now start */
+ cq_expect_completion(cqv, tag(0x201), 1);
+ cq_expect_completion(cqv, tag(0x401), 1);
+ cq_verify(cqv);
+
+ /* listen for close on the server call to probe for finishing */
+ op = ops;
+ op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
+ op->data.recv_close_on_server.cancelled = &was_cancelled2;
+ op->flags = 0;
+ op++;
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(server_call2, ops,
+ (size_t)(op - ops),
+ tag(0x402), NULL));
+
+ /* shutdown second server: we should see nothing */
+ grpc_server_shutdown_and_notify(server2, cq, tag(0xdead2));
+ cq_verify_empty(cqv);
+
+ grpc_call_cancel(call1, NULL);
+ grpc_call_cancel(call2, NULL);
+
+ /* now everything else should finish */
+ cq_expect_completion(cqv, tag(0x102), 1);
+ cq_expect_completion(cqv, tag(0x202), 1);
+ cq_expect_completion(cqv, tag(0x302), 1);
+ cq_expect_completion(cqv, tag(0x402), 1);
+ cq_expect_completion(cqv, tag(0xdead1), 1);
+ cq_expect_completion(cqv, tag(0xdead2), 1);
+ cq_verify(cqv);
+
+ grpc_call_destroy(call1);
+ grpc_call_destroy(call2);
+ grpc_call_destroy(server_call1);
+ grpc_call_destroy(server_call2);
+ grpc_server_destroy(server1);
+ grpc_server_destroy(server2);
+ grpc_channel_destroy(chan);
+
+ grpc_metadata_array_destroy(&trailing_metadata_recv1);
+ grpc_metadata_array_destroy(&request_metadata1);
+ grpc_call_details_destroy(&request_details1);
+ gpr_free(details1);
+ grpc_metadata_array_destroy(&trailing_metadata_recv2);
+ grpc_metadata_array_destroy(&request_metadata2);
+ grpc_call_details_destroy(&request_details2);
+ gpr_free(details2);
+
+ cq_verifier_destroy(cqv);
+ grpc_completion_queue_destroy(cq);
+
+ grpc_shutdown();
+ gpr_mu_destroy(&g_mu);
+
+ return 0;
+}
diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc
index 245b342a69..94541f9a45 100644
--- a/test/cpp/end2end/thread_stress_test.cc
+++ b/test/cpp/end2end/thread_stress_test.cc
@@ -179,6 +179,7 @@ template <class Service>
class CommonStressTest {
public:
CommonStressTest() : kMaxMessageSize_(8192) {}
+ virtual ~CommonStressTest() {}
virtual void SetUp() = 0;
virtual void TearDown() = 0;
void ResetStub() {
diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json
index 4bad249f41..af6f7f4fc3 100644
--- a/tools/run_tests/sources_and_headers.json
+++ b/tools/run_tests/sources_and_headers.json
@@ -393,6 +393,22 @@
{
"deps": [
"gpr",
+ "gpr_test_util",
+ "grpc",
+ "grpc_test_util"
+ ],
+ "headers": [],
+ "language": "c",
+ "name": "goaway_server_test",
+ "src": [
+ "test/core/end2end/goaway_server_test.c"
+ ],
+ "third_party": false,
+ "type": "target"
+ },
+ {
+ "deps": [
+ "gpr",
"gpr_test_util"
],
"headers": [],
diff --git a/tools/run_tests/stress_test/STRESS_CLIENT_SPEC.md b/tools/run_tests/stress_test/STRESS_CLIENT_SPEC.md
index c4c9f14513..cebe5460b1 100644
--- a/tools/run_tests/stress_test/STRESS_CLIENT_SPEC.md
+++ b/tools/run_tests/stress_test/STRESS_CLIENT_SPEC.md
@@ -17,7 +17,7 @@ This document specifies the features a stress test client should implement in or
Parameter | Description
----------------------|---------------------------------
-`--server_address` | The stress client should accept a list of server addresses in the following format:<br> ```<name_1>:<port_1>,<name_2>:<port_2>..<name_N>:<port_N>``` <br> _Note:_ `<name>` can be either server name or IP address.<br><br>_Type:_ string <br>_default:_ ```localhost:8080``` <br>_Example:_ ``foo.foobar.com:8080,bar.foobar.com:8080`` <br><br> Currently, the stress test framework only passes one server address to the client.
+`--server_addresses` | The stress client should accept a list of server addresses in the following format:<br> ```<name_1>:<port_1>,<name_2>:<port_2>..<name_N>:<port_N>``` <br> _Note:_ `<name>` can be either server name or IP address.<br><br>_Type:_ string <br>_default:_ ```localhost:8080``` <br>_Example:_ ``foo.foobar.com:8080,bar.foobar.com:8080`` <br><br> Currently, the stress test framework only passes one server address to the client.
`--test_cases` | List of test cases along with the relative weights in the following format:<br> `<testcase_1:w_1>,<testcase_2:w_2>...<testcase_n:w_n>`. <br> The test cases names are the same as those currently used by the interop clients<br><br>_Type:_ string <br>_Example:_ `empty_unary:20,large_unary:10,empty_stream:70` <br>(The stress client would then make `empty_unary` calls 20% of the time, `large_unary` calls 10% of the time and `empty_stream` calls 70% of the time.) <br>_Note:_ The weights need not add up to 100.
`--test_duration-secs` | The test duration in seconds. A value of -1 means that the test should run forever until forcefully terminated. <br>_Type:_ int <br>_default:_ -1
`--num_channels_per_server` | Number of channels (i.e connections) to each server. <br> _Type:_ int <br> _default:_ 1 <br><br> _Note:_ Unfortunately, the term `channel` is used differently in `grpc-java` and `C based grpc`. In this context, this really means "number of connections to the server"
diff --git a/tools/run_tests/tests.json b/tools/run_tests/tests.json
index e516543dae..189bd662e3 100644
--- a/tools/run_tests/tests.json
+++ b/tools/run_tests/tests.json
@@ -437,6 +437,25 @@
"ci_platforms": [
"linux",
"mac",
+ "posix"
+ ],
+ "cpu_cost": 0.1,
+ "exclude_configs": [],
+ "flaky": false,
+ "gtest": false,
+ "language": "c",
+ "name": "goaway_server_test",
+ "platforms": [
+ "linux",
+ "mac",
+ "posix"
+ ]
+ },
+ {
+ "args": [],
+ "ci_platforms": [
+ "linux",
+ "mac",
"posix",
"windows"
],