diff options
author | Yuchen Zeng <y-zeng@users.noreply.github.com> | 2017-06-08 13:17:02 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-08 13:17:02 -0700 |
commit | 8f3d02106b72783f61430c84d3501ed3d88b3415 (patch) | |
tree | 94c4a489125aa3782dbdfc92debda55e32536af7 /test/core/client_channel | |
parent | c055a79262b52f8a06c92b706bff3686e062b081 (diff) | |
parent | a2c468d691a7e38df217ce2a6f102bd32a49b1c5 (diff) |
Merge pull request #11237 from y-zeng/srv_record
Support grpclb address in the c-ares resolver
Diffstat (limited to 'test/core/client_channel')
-rw-r--r-- | test/core/client_channel/resolvers/dns_resolver_connectivity_test.c | 23 | ||||
-rw-r--r-- | test/core/client_channel/resolvers/dns_resolver_test.c | 7 |
2 files changed, 29 insertions, 1 deletions
diff --git a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.c b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.c index 99fccd055d..1407628198 100644 --- a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.c +++ b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.c @@ -21,7 +21,9 @@ #include <grpc/grpc.h> #include <grpc/support/alloc.h> +#include "src/core/ext/filters/client_channel/lb_policy_factory.h" #include "src/core/ext/filters/client_channel/resolver.h" +#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h" #include "src/core/ext/filters/client_channel/resolver_registry.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/iomgr/combiner.h" @@ -55,6 +57,26 @@ static void my_resolve_address(grpc_exec_ctx *exec_ctx, const char *addr, grpc_closure_sched(exec_ctx, on_done, error); } +static grpc_ares_request *my_dns_lookup_ares( + grpc_exec_ctx *exec_ctx, const char *dns_server, const char *addr, + const char *default_port, grpc_pollset_set *interested_parties, + grpc_closure *on_done, grpc_lb_addresses **lb_addrs, bool check_grpclb) { + gpr_mu_lock(&g_mu); + GPR_ASSERT(0 == strcmp("test", addr)); + grpc_error *error = GRPC_ERROR_NONE; + if (g_fail_resolution) { + g_fail_resolution = false; + gpr_mu_unlock(&g_mu); + error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Forced Failure"); + } else { + gpr_mu_unlock(&g_mu); + *lb_addrs = grpc_lb_addresses_create(1, NULL); + grpc_lb_addresses_set_address(*lb_addrs, 0, NULL, 0, false, NULL, NULL); + } + grpc_closure_sched(exec_ctx, on_done, error); + return NULL; +} + static grpc_resolver *create_resolver(grpc_exec_ctx *exec_ctx, const char *name) { grpc_resolver_factory *factory = grpc_resolver_factory_lookup("dns"); @@ -125,6 +147,7 @@ int main(int argc, char **argv) { gpr_mu_init(&g_mu); g_combiner = grpc_combiner_create(NULL); grpc_resolve_address = my_resolve_address; + grpc_dns_lookup_ares = my_dns_lookup_ares; grpc_channel_args *result = (grpc_channel_args *)1; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; diff --git a/test/core/client_channel/resolvers/dns_resolver_test.c b/test/core/client_channel/resolvers/dns_resolver_test.c index 8fc8bde438..877f8d9e88 100644 --- a/test/core/client_channel/resolvers/dns_resolver_test.c +++ b/test/core/client_channel/resolvers/dns_resolver_test.c @@ -20,6 +20,7 @@ #include <grpc/support/log.h> +#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h" #include "src/core/ext/filters/client_channel/resolver_registry.h" #include "src/core/lib/iomgr/combiner.h" #include "test/core/util/test_config.h" @@ -73,7 +74,11 @@ int main(int argc, char **argv) { test_succeeds(dns, "dns:10.2.1.1"); test_succeeds(dns, "dns:10.2.1.1:1234"); test_succeeds(dns, "ipv4:www.google.com"); - test_fails(dns, "ipv4://8.8.8.8/8.8.8.8:8888"); + if (grpc_resolve_address == grpc_resolve_address_ares) { + test_succeeds(dns, "ipv4://8.8.8.8/8.8.8.8:8888"); + } else { + test_fails(dns, "ipv4://8.8.8.8/8.8.8.8:8888"); + } grpc_resolver_factory_unref(dns); { |