Skip to content

Commit

Permalink
Merge pull request grpc#8205 from ctiller/crashy
Browse files Browse the repository at this point in the history
Add (slightly cleaned up) variant of user contributed test
  • Loading branch information
ctiller committed Oct 3, 2016
2 parents c9742d3 + af76e65 commit 0368e3d
Show file tree
Hide file tree
Showing 8 changed files with 459 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,7 @@ client_fuzzer: $(BINDIR)/$(CONFIG)/client_fuzzer
combiner_test: $(BINDIR)/$(CONFIG)/combiner_test
compression_test: $(BINDIR)/$(CONFIG)/compression_test
concurrent_connectivity_test: $(BINDIR)/$(CONFIG)/concurrent_connectivity_test
connection_refused_test: $(BINDIR)/$(CONFIG)/connection_refused_test
dns_resolver_connectivity_test: $(BINDIR)/$(CONFIG)/dns_resolver_connectivity_test
dns_resolver_test: $(BINDIR)/$(CONFIG)/dns_resolver_test
dualstack_socket_test: $(BINDIR)/$(CONFIG)/dualstack_socket_test
Expand Down Expand Up @@ -1249,6 +1250,7 @@ buildtests_c: privatelibs_c \
$(BINDIR)/$(CONFIG)/combiner_test \
$(BINDIR)/$(CONFIG)/compression_test \
$(BINDIR)/$(CONFIG)/concurrent_connectivity_test \
$(BINDIR)/$(CONFIG)/connection_refused_test \
$(BINDIR)/$(CONFIG)/dns_resolver_connectivity_test \
$(BINDIR)/$(CONFIG)/dns_resolver_test \
$(BINDIR)/$(CONFIG)/dualstack_socket_test \
Expand Down Expand Up @@ -1575,6 +1577,8 @@ test_c: buildtests_c
$(Q) $(BINDIR)/$(CONFIG)/compression_test || ( echo test compression_test failed ; exit 1 )
$(E) "[RUN] Testing concurrent_connectivity_test"
$(Q) $(BINDIR)/$(CONFIG)/concurrent_connectivity_test || ( echo test concurrent_connectivity_test failed ; exit 1 )
$(E) "[RUN] Testing connection_refused_test"
$(Q) $(BINDIR)/$(CONFIG)/connection_refused_test || ( echo test connection_refused_test failed ; exit 1 )
$(E) "[RUN] Testing dns_resolver_connectivity_test"
$(Q) $(BINDIR)/$(CONFIG)/dns_resolver_connectivity_test || ( echo test dns_resolver_connectivity_test failed ; exit 1 )
$(E) "[RUN] Testing dns_resolver_test"
Expand Down Expand Up @@ -7355,6 +7359,38 @@ endif
endif


CONNECTION_REFUSED_TEST_SRC = \
test/core/end2end/connection_refused_test.c \

CONNECTION_REFUSED_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(CONNECTION_REFUSED_TEST_SRC))))
ifeq ($(NO_SECURE),true)

# You can't build secure targets if you don't have OpenSSL.

$(BINDIR)/$(CONFIG)/connection_refused_test: openssl_dep_error

else



$(BINDIR)/$(CONFIG)/connection_refused_test: $(CONNECTION_REFUSED_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) $(CONNECTION_REFUSED_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)/connection_refused_test

endif

$(OBJDIR)/$(CONFIG)/test/core/end2end/connection_refused_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a

deps_connection_refused_test: $(CONNECTION_REFUSED_TEST_OBJS:.o=.dep)

ifneq ($(NO_SECURE),true)
ifneq ($(NO_DEPS),true)
-include $(CONNECTION_REFUSED_TEST_OBJS:.o=.dep)
endif
endif


DNS_RESOLVER_CONNECTIVITY_TEST_SRC = \
test/core/client_config/resolvers/dns_resolver_connectivity_test.c \

Expand Down
11 changes: 11 additions & 0 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,17 @@ targets:
- grpc
- gpr_test_util
- gpr
- name: connection_refused_test
cpu_cost: 0.1
build: test
language: c
src:
- test/core/end2end/connection_refused_test.c
deps:
- grpc_test_util
- grpc
- gpr_test_util
- gpr
- name: dns_resolver_connectivity_test
cpu_cost: 0.1
build: test
Expand Down
128 changes: 128 additions & 0 deletions test/core/end2end/connection_refused_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
*
* 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 <string.h>

#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/host_port.h>
#include <grpc/support/log.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 void run_test(bool fail_fast) {
grpc_channel *chan;
grpc_call *call;
gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(2);
grpc_completion_queue *cq;
cq_verifier *cqv;
grpc_op ops[6];
grpc_op *op;
grpc_metadata_array trailing_metadata_recv;
grpc_status_code status;
char *details = NULL;
size_t details_capacity = 0;

gpr_log(GPR_INFO, "TEST: fail_fast=%d", fail_fast);

grpc_init();

grpc_metadata_array_init(&trailing_metadata_recv);

cq = grpc_completion_queue_create(NULL);
cqv = cq_verifier_create(cq);

/* create a call, channel to a port which will refuse connection */
int port = grpc_pick_unused_port_or_die();
char *addr;
gpr_join_host_port(&addr, "localhost", port);

chan = grpc_insecure_channel_create(addr, NULL, NULL);
call = grpc_channel_create_call(chan, NULL, GRPC_PROPAGATE_DEFAULTS, cq,
"/Foo", "nonexistant", deadline, NULL);

gpr_free(addr);

memset(ops, 0, sizeof(ops));
op = ops;
op->op = GRPC_OP_SEND_INITIAL_METADATA;
op->data.send_initial_metadata.count = 0;
op->flags = fail_fast ? 0 : GRPC_INITIAL_METADATA_IGNORE_CONNECTIVITY;
op->reserved = NULL;
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->reserved = NULL;
op++;
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(
call, ops, (size_t)(op - ops), tag(1), NULL));
/* verify that all tags get completed */
CQ_EXPECT_COMPLETION(cqv, tag(1), 1);
cq_verify(cqv);

if (fail_fast) {
GPR_ASSERT(status == GRPC_STATUS_UNAVAILABLE);
} else {
GPR_ASSERT(status == GRPC_STATUS_DEADLINE_EXCEEDED);
}

grpc_completion_queue_shutdown(cq);
while (
grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_REALTIME), NULL)
.type != GRPC_QUEUE_SHUTDOWN)
;
grpc_completion_queue_destroy(cq);
grpc_call_destroy(call);
grpc_channel_destroy(chan);
cq_verifier_destroy(cqv);

gpr_free(details);
grpc_metadata_array_destroy(&trailing_metadata_recv);

grpc_shutdown();
}

int main(int argc, char **argv) {
grpc_test_init(argc, argv);
run_test(true);
run_test(false);
return 0;
}
16 changes: 16 additions & 0 deletions tools/run_tests/sources_and_headers.json
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,22 @@
"headers": [],
"is_filegroup": false,
"language": "c",
"name": "connection_refused_test",
"src": [
"test/core/end2end/connection_refused_test.c"
],
"third_party": false,
"type": "target"
},
{
"deps": [
"gpr",
"gpr_test_util",
"grpc",
"grpc_test_util"
],
"headers": [],
"language": "c",
"name": "dns_resolver_connectivity_test",
"src": [
"test/core/client_config/resolvers/dns_resolver_connectivity_test.c"
Expand Down
21 changes: 21 additions & 0 deletions tools/run_tests/tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,27 @@
"windows"
]
},
{
"args": [],
"ci_platforms": [
"linux",
"mac",
"posix",
"windows"
],
"cpu_cost": 0.1,
"exclude_configs": [],
"flaky": false,
"gtest": false,
"language": "c",
"name": "connection_refused_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
]
},
{
"args": [],
"ci_platforms": [
Expand Down
27 changes: 27 additions & 0 deletions vsprojects/buildtests_c.sln
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,17 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "connection_prefix_bad_clien
{B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} = {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "connection_refused_test", "vcxproj\test\connection_refused_test\connection_refused_test.vcxproj", "{961DFABF-18F2-7D46-4D69-B82A5E9A78B2}"
ProjectSection(myProperties) = preProject
lib = "False"
EndProjectSection
ProjectSection(ProjectDependencies) = postProject
{17BCAFC0-5FDC-4C94-AEB9-95F3E220614B} = {17BCAFC0-5FDC-4C94-AEB9-95F3E220614B}
{29D16885-7228-4C31-81ED-5F9187C7F2A9} = {29D16885-7228-4C31-81ED-5F9187C7F2A9}
{EAB0A629-17A9-44DB-B5FF-E91A721FE037} = {EAB0A629-17A9-44DB-B5FF-E91A721FE037}
{B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} = {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dns_resolver_connectivity_test", "vcxproj\test\dns_resolver_connectivity_test\dns_resolver_connectivity_test.vcxproj", "{F7B6FE68-E847-D7CA-4062-E737E542BCC3}"
ProjectSection(myProperties) = preProject
lib = "False"
Expand Down Expand Up @@ -1855,6 +1866,22 @@ Global
{AF9D0EB2-2A53-B815-3A63-E82C7F91DB29}.Release-DLL|Win32.Build.0 = Release|Win32
{AF9D0EB2-2A53-B815-3A63-E82C7F91DB29}.Release-DLL|x64.ActiveCfg = Release|x64
{AF9D0EB2-2A53-B815-3A63-E82C7F91DB29}.Release-DLL|x64.Build.0 = Release|x64
{961DFABF-18F2-7D46-4D69-B82A5E9A78B2}.Debug|Win32.ActiveCfg = Debug|Win32
{961DFABF-18F2-7D46-4D69-B82A5E9A78B2}.Debug|x64.ActiveCfg = Debug|x64
{961DFABF-18F2-7D46-4D69-B82A5E9A78B2}.Release|Win32.ActiveCfg = Release|Win32
{961DFABF-18F2-7D46-4D69-B82A5E9A78B2}.Release|x64.ActiveCfg = Release|x64
{961DFABF-18F2-7D46-4D69-B82A5E9A78B2}.Debug|Win32.Build.0 = Debug|Win32
{961DFABF-18F2-7D46-4D69-B82A5E9A78B2}.Debug|x64.Build.0 = Debug|x64
{961DFABF-18F2-7D46-4D69-B82A5E9A78B2}.Release|Win32.Build.0 = Release|Win32
{961DFABF-18F2-7D46-4D69-B82A5E9A78B2}.Release|x64.Build.0 = Release|x64
{961DFABF-18F2-7D46-4D69-B82A5E9A78B2}.Debug-DLL|Win32.ActiveCfg = Debug|Win32
{961DFABF-18F2-7D46-4D69-B82A5E9A78B2}.Debug-DLL|Win32.Build.0 = Debug|Win32
{961DFABF-18F2-7D46-4D69-B82A5E9A78B2}.Debug-DLL|x64.ActiveCfg = Debug|x64
{961DFABF-18F2-7D46-4D69-B82A5E9A78B2}.Debug-DLL|x64.Build.0 = Debug|x64
{961DFABF-18F2-7D46-4D69-B82A5E9A78B2}.Release-DLL|Win32.ActiveCfg = Release|Win32
{961DFABF-18F2-7D46-4D69-B82A5E9A78B2}.Release-DLL|Win32.Build.0 = Release|Win32
{961DFABF-18F2-7D46-4D69-B82A5E9A78B2}.Release-DLL|x64.ActiveCfg = Release|x64
{961DFABF-18F2-7D46-4D69-B82A5E9A78B2}.Release-DLL|x64.Build.0 = Release|x64
{F7B6FE68-E847-D7CA-4062-E737E542BCC3}.Debug|Win32.ActiveCfg = Debug|Win32
{F7B6FE68-E847-D7CA-4062-E737E542BCC3}.Debug|x64.ActiveCfg = Debug|x64
{F7B6FE68-E847-D7CA-4062-E737E542BCC3}.Release|Win32.ActiveCfg = Release|Win32
Expand Down
Loading

0 comments on commit 0368e3d

Please sign in to comment.