diff --git a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c index 74d2015e5c2..f232e0460b6 100644 --- a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +++ b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c @@ -53,10 +53,10 @@ typedef struct { gpr_refcount refs; /** load balancing policy name */ char *lb_policy_name; - + /** the path component of the uri passed in */ + char *target_name; /** the addresses that we've 'resolved' */ grpc_lb_addresses *addresses; - /** mutex guarding the rest of the state */ gpr_mu mu; /** have we published? */ @@ -121,7 +121,8 @@ static void sockaddr_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx, if (r->next_completion != NULL && !r->published) { r->published = true; *r->target_result = grpc_resolver_result_create( - "", grpc_lb_addresses_copy(r->addresses, NULL /* user_data_copy */), + r->target_name, + grpc_lb_addresses_copy(r->addresses, NULL /* user_data_copy */), r->lb_policy_name, NULL); grpc_exec_ctx_sched(exec_ctx, r->next_completion, GRPC_ERROR_NONE, NULL); r->next_completion = NULL; @@ -133,6 +134,7 @@ static void sockaddr_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *gr) { gpr_mu_destroy(&r->mu); grpc_lb_addresses_destroy(r->addresses, NULL /* user_data_destroy */); gpr_free(r->lb_policy_name); + gpr_free(r->target_name); gpr_free(r); } @@ -220,10 +222,12 @@ static grpc_resolver *sockaddr_create( if (errors_found) break; } + r->target_name = gpr_strdup(args->uri->path); gpr_slice_buffer_destroy(&path_parts); gpr_slice_unref(path_slice); if (errors_found) { gpr_free(r->lb_policy_name); + gpr_free(r->target_name); grpc_lb_addresses_destroy(r->addresses, NULL /* user_data_destroy */); gpr_free(r); return NULL; diff --git a/test/core/client_config/resolvers/sockaddr_resolver_test.c b/test/core/client_config/resolvers/sockaddr_resolver_test.c index d8430d39c4c..b5d96efa1d9 100644 --- a/test/core/client_config/resolvers/sockaddr_resolver_test.c +++ b/test/core/client_config/resolvers/sockaddr_resolver_test.c @@ -33,11 +33,28 @@ #include +#include #include +#include #include "src/core/ext/client_config/resolver_registry.h" +#include "src/core/ext/client_config/resolver_result.h" + #include "test/core/util/test_config.h" +typedef struct on_resolution_arg { + char *expected_server_name; + grpc_resolver_result *resolver_result; +} on_resolution_arg; + +void on_resolution_cb(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { + on_resolution_arg *res = arg; + const char *server_name = + grpc_resolver_result_get_server_name(res->resolver_result); + GPR_ASSERT(strcmp(res->expected_server_name, server_name) == 0); + grpc_resolver_result_unref(exec_ctx, res->resolver_result); +} + static void test_succeeds(grpc_resolver_factory *factory, const char *string) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_uri *uri = grpc_uri_parse(string, 0); @@ -50,9 +67,18 @@ static void test_succeeds(grpc_resolver_factory *factory, const char *string) { args.uri = uri; resolver = grpc_resolver_factory_create_resolver(factory, &args); GPR_ASSERT(resolver != NULL); + + on_resolution_arg on_res_arg; + memset(&on_res_arg, 0, sizeof(on_res_arg)); + on_res_arg.expected_server_name = uri->path; + grpc_closure *on_resolution = + grpc_closure_create(on_resolution_cb, &on_res_arg); + + grpc_resolver_next(&exec_ctx, resolver, &on_res_arg.resolver_result, + on_resolution); GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test_succeeds"); - grpc_uri_destroy(uri); grpc_exec_ctx_finish(&exec_ctx); + grpc_uri_destroy(uri); } static void test_fails(grpc_resolver_factory *factory, const char *string) {