diff options
Diffstat (limited to 'test/core/client_channel/resolvers')
4 files changed, 100 insertions, 88 deletions
diff --git a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc index 18a795fbcb..dcf315eba5 100644 --- a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc +++ b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc @@ -35,7 +35,8 @@ static gpr_mu g_mu; static bool g_fail_resolution = true; static grpc_combiner* g_combiner; -static void my_resolve_address(const char* addr, const char* default_port, +static void my_resolve_address(grpc_exec_ctx* exec_ctx, const char* addr, + const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addrs) { @@ -54,13 +55,13 @@ static void my_resolve_address(const char* addr, const char* default_port, gpr_malloc(sizeof(*(*addrs)->addrs))); (*addrs)->addrs[0].len = 123; } - GRPC_CLOSURE_SCHED(on_done, error); + GRPC_CLOSURE_SCHED(exec_ctx, on_done, error); } static grpc_ares_request* my_dns_lookup_ares( - 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, + 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, char** service_config_json) { gpr_mu_lock(&g_mu); GPR_ASSERT(0 == strcmp("test", addr)); @@ -75,26 +76,27 @@ static grpc_ares_request* my_dns_lookup_ares( grpc_lb_addresses_set_address(*lb_addrs, 0, nullptr, 0, false, nullptr, nullptr); } - GRPC_CLOSURE_SCHED(on_done, error); + GRPC_CLOSURE_SCHED(exec_ctx, on_done, error); return nullptr; } -static grpc_resolver* create_resolver(const char* name) { +static grpc_resolver* create_resolver(grpc_exec_ctx* exec_ctx, + const char* name) { grpc_resolver_factory* factory = grpc_resolver_factory_lookup("dns"); - grpc_uri* uri = grpc_uri_parse(name, 0); + grpc_uri* uri = grpc_uri_parse(exec_ctx, name, 0); GPR_ASSERT(uri); grpc_resolver_args args; memset(&args, 0, sizeof(args)); args.uri = uri; args.combiner = g_combiner; grpc_resolver* resolver = - grpc_resolver_factory_create_resolver(factory, &args); + grpc_resolver_factory_create_resolver(exec_ctx, factory, &args); grpc_resolver_factory_unref(factory); grpc_uri_destroy(uri); return resolver; } -static void on_done(void* ev, grpc_error* error) { +static void on_done(grpc_exec_ctx* exec_ctx, void* ev, grpc_error* error) { gpr_event_set((gpr_event*)ev, (void*)1); } @@ -105,8 +107,9 @@ static bool wait_loop(int deadline_seconds, gpr_event* ev) { if (gpr_event_wait(ev, grpc_timeout_seconds_to_deadline(1))) return true; deadline_seconds--; - grpc_core::ExecCtx exec_ctx; - grpc_timer_check(nullptr); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_timer_check(&exec_ctx, nullptr); + grpc_exec_ctx_finish(&exec_ctx); } return false; } @@ -117,14 +120,16 @@ typedef struct next_args { grpc_closure* on_complete; } next_args; -static void call_resolver_next_now_lock_taken(void* arg, +static void call_resolver_next_now_lock_taken(grpc_exec_ctx* exec_ctx, + void* arg, grpc_error* error_unused) { next_args* a = static_cast<next_args*>(arg); - grpc_resolver_next_locked(a->resolver, a->result, a->on_complete); + grpc_resolver_next_locked(exec_ctx, a->resolver, a->result, a->on_complete); gpr_free(a); } -static void call_resolver_next_after_locking(grpc_resolver* resolver, +static void call_resolver_next_after_locking(grpc_exec_ctx* exec_ctx, + grpc_resolver* resolver, grpc_channel_args** result, grpc_closure* on_complete) { next_args* a = static_cast<next_args*>(gpr_malloc(sizeof(*a))); @@ -132,6 +137,7 @@ static void call_resolver_next_after_locking(grpc_resolver* resolver, a->result = result; a->on_complete = on_complete; GRPC_CLOSURE_SCHED( + exec_ctx, GRPC_CLOSURE_CREATE(call_resolver_next_now_lock_taken, a, grpc_combiner_scheduler(resolver->combiner)), GRPC_ERROR_NONE); @@ -147,31 +153,30 @@ int main(int argc, char** argv) { grpc_dns_lookup_ares = my_dns_lookup_ares; grpc_channel_args* result = (grpc_channel_args*)1; - { - grpc_core::ExecCtx exec_ctx; - grpc_resolver* resolver = create_resolver("dns:test"); - gpr_event ev1; - gpr_event_init(&ev1); - call_resolver_next_after_locking( - resolver, &result, - GRPC_CLOSURE_CREATE(on_done, &ev1, grpc_schedule_on_exec_ctx)); - grpc_core::ExecCtx::Get()->Flush(); - GPR_ASSERT(wait_loop(5, &ev1)); - GPR_ASSERT(result == nullptr); - - gpr_event ev2; - gpr_event_init(&ev2); - call_resolver_next_after_locking( - resolver, &result, - GRPC_CLOSURE_CREATE(on_done, &ev2, grpc_schedule_on_exec_ctx)); - grpc_core::ExecCtx::Get()->Flush(); - GPR_ASSERT(wait_loop(30, &ev2)); - GPR_ASSERT(result != nullptr); - - grpc_channel_args_destroy(result); - GRPC_RESOLVER_UNREF(resolver, "test"); - GRPC_COMBINER_UNREF(g_combiner, "test"); - } + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_resolver* resolver = create_resolver(&exec_ctx, "dns:test"); + gpr_event ev1; + gpr_event_init(&ev1); + call_resolver_next_after_locking( + &exec_ctx, resolver, &result, + GRPC_CLOSURE_CREATE(on_done, &ev1, grpc_schedule_on_exec_ctx)); + grpc_exec_ctx_flush(&exec_ctx); + GPR_ASSERT(wait_loop(5, &ev1)); + GPR_ASSERT(result == nullptr); + + gpr_event ev2; + gpr_event_init(&ev2); + call_resolver_next_after_locking( + &exec_ctx, resolver, &result, + GRPC_CLOSURE_CREATE(on_done, &ev2, grpc_schedule_on_exec_ctx)); + grpc_exec_ctx_flush(&exec_ctx); + GPR_ASSERT(wait_loop(30, &ev2)); + GPR_ASSERT(result != nullptr); + + grpc_channel_args_destroy(&exec_ctx, result); + GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test"); + GRPC_COMBINER_UNREF(&exec_ctx, g_combiner, "test"); + grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); gpr_mu_destroy(&g_mu); diff --git a/test/core/client_channel/resolvers/dns_resolver_test.cc b/test/core/client_channel/resolvers/dns_resolver_test.cc index 80667908ef..4c040caeb9 100644 --- a/test/core/client_channel/resolvers/dns_resolver_test.cc +++ b/test/core/client_channel/resolvers/dns_resolver_test.cc @@ -28,8 +28,8 @@ static grpc_combiner* g_combiner; static void test_succeeds(grpc_resolver_factory* factory, const char* string) { - grpc_core::ExecCtx exec_ctx; - grpc_uri* uri = grpc_uri_parse(string, 0); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_uri* uri = grpc_uri_parse(&exec_ctx, string, 0); grpc_resolver_args args; grpc_resolver* resolver; gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", string, @@ -38,15 +38,16 @@ static void test_succeeds(grpc_resolver_factory* factory, const char* string) { memset(&args, 0, sizeof(args)); args.uri = uri; args.combiner = g_combiner; - resolver = grpc_resolver_factory_create_resolver(factory, &args); + resolver = grpc_resolver_factory_create_resolver(&exec_ctx, factory, &args); GPR_ASSERT(resolver != nullptr); - GRPC_RESOLVER_UNREF(resolver, "test_succeeds"); + GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test_succeeds"); grpc_uri_destroy(uri); + grpc_exec_ctx_finish(&exec_ctx); } static void test_fails(grpc_resolver_factory* factory, const char* string) { - grpc_core::ExecCtx exec_ctx; - grpc_uri* uri = grpc_uri_parse(string, 0); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_uri* uri = grpc_uri_parse(&exec_ctx, string, 0); grpc_resolver_args args; grpc_resolver* resolver; gpr_log(GPR_DEBUG, "test: '%s' should be invalid for '%s'", string, @@ -55,9 +56,10 @@ static void test_fails(grpc_resolver_factory* factory, const char* string) { memset(&args, 0, sizeof(args)); args.uri = uri; args.combiner = g_combiner; - resolver = grpc_resolver_factory_create_resolver(factory, &args); + resolver = grpc_resolver_factory_create_resolver(&exec_ctx, factory, &args); GPR_ASSERT(resolver == nullptr); grpc_uri_destroy(uri); + grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { @@ -80,8 +82,9 @@ int main(int argc, char** argv) { grpc_resolver_factory_unref(dns); { - grpc_core::ExecCtx exec_ctx; - GRPC_COMBINER_UNREF(g_combiner, "test"); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + GRPC_COMBINER_UNREF(&exec_ctx, g_combiner, "test"); + grpc_exec_ctx_finish(&exec_ctx); } grpc_shutdown(); diff --git a/test/core/client_channel/resolvers/fake_resolver_test.cc b/test/core/client_channel/resolvers/fake_resolver_test.cc index d85cbb1d03..d5538e9621 100644 --- a/test/core/client_channel/resolvers/fake_resolver_test.cc +++ b/test/core/client_channel/resolvers/fake_resolver_test.cc @@ -33,7 +33,7 @@ #include "test/core/util/test_config.h" static grpc_resolver* build_fake_resolver( - grpc_combiner* combiner, + grpc_exec_ctx* exec_ctx, grpc_combiner* combiner, grpc_fake_resolver_response_generator* response_generator) { grpc_resolver_factory* factory = grpc_resolver_factory_lookup("fake"); grpc_arg generator_arg = @@ -44,7 +44,7 @@ static grpc_resolver* build_fake_resolver( args.args = &channel_args; args.combiner = combiner; grpc_resolver* resolver = - grpc_resolver_factory_create_resolver(factory, &args); + grpc_resolver_factory_create_resolver(exec_ctx, factory, &args); grpc_resolver_factory_unref(factory); return resolver; } @@ -55,7 +55,7 @@ typedef struct on_resolution_arg { gpr_event ev; } on_resolution_arg; -void on_resolution_cb(void* arg, grpc_error* error) { +void on_resolution_cb(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { on_resolution_arg* res = static_cast<on_resolution_arg*>(arg); // We only check the addresses channel arg because that's the only one // explicitly set by the test via @@ -66,23 +66,24 @@ void on_resolution_cb(void* arg, grpc_error* error) { grpc_lb_addresses_find_channel_arg(res->expected_resolver_result); GPR_ASSERT( grpc_lb_addresses_cmp(actual_lb_addresses, expected_lb_addresses) == 0); - grpc_channel_args_destroy(res->resolver_result); - grpc_channel_args_destroy(res->expected_resolver_result); + grpc_channel_args_destroy(exec_ctx, res->resolver_result); + grpc_channel_args_destroy(exec_ctx, res->expected_resolver_result); gpr_event_set(&res->ev, (void*)1); } static void test_fake_resolver() { - grpc_core::ExecCtx exec_ctx; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_combiner* combiner = grpc_combiner_create(); // Create resolver. grpc_fake_resolver_response_generator* response_generator = grpc_fake_resolver_response_generator_create(); - grpc_resolver* resolver = build_fake_resolver(combiner, response_generator); + grpc_resolver* resolver = + build_fake_resolver(&exec_ctx, combiner, response_generator); GPR_ASSERT(resolver != nullptr); // Setup expectations. - grpc_uri* uris[] = {grpc_uri_parse("ipv4:10.2.1.1:1234", true), - grpc_uri_parse("ipv4:127.0.0.1:4321", true)}; + grpc_uri* uris[] = {grpc_uri_parse(&exec_ctx, "ipv4:10.2.1.1:1234", true), + grpc_uri_parse(&exec_ctx, "ipv4:127.0.0.1:4321", true)}; const char* balancer_names[] = {"name1", "name2"}; const bool is_balancer[] = {true, false}; grpc_lb_addresses* addresses = grpc_lb_addresses_create(3, nullptr); @@ -95,7 +96,7 @@ static void test_fake_resolver() { grpc_lb_addresses_create_channel_arg(addresses); grpc_channel_args* results = grpc_channel_args_copy_and_add(nullptr, &addresses_arg, 1); - grpc_lb_addresses_destroy(addresses); + grpc_lb_addresses_destroy(&exec_ctx, addresses); on_resolution_arg on_res_arg; memset(&on_res_arg, 0, sizeof(on_res_arg)); on_res_arg.expected_resolver_result = results; @@ -105,16 +106,17 @@ static void test_fake_resolver() { // Set resolver results and trigger first resolution. on_resolution_cb // performs the checks. - grpc_fake_resolver_response_generator_set_response(response_generator, - results); - grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result, + grpc_fake_resolver_response_generator_set_response( + &exec_ctx, response_generator, results); + grpc_resolver_next_locked(&exec_ctx, resolver, &on_res_arg.resolver_result, on_resolution); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); GPR_ASSERT(gpr_event_wait(&on_res_arg.ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); // Setup update. - grpc_uri* uris_update[] = {grpc_uri_parse("ipv4:192.168.1.0:31416", true)}; + grpc_uri* uris_update[] = { + grpc_uri_parse(&exec_ctx, "ipv4:192.168.1.0:31416", true)}; const char* balancer_names_update[] = {"name3"}; const bool is_balancer_update[] = {false}; grpc_lb_addresses* addresses_update = grpc_lb_addresses_create(1, nullptr); @@ -129,7 +131,7 @@ static void test_fake_resolver() { grpc_lb_addresses_create_channel_arg(addresses_update); grpc_channel_args* results_update = grpc_channel_args_copy_and_add(nullptr, &addresses_update_arg, 1); - grpc_lb_addresses_destroy(addresses_update); + grpc_lb_addresses_destroy(&exec_ctx, addresses_update); // Setup expectations for the update. on_resolution_arg on_res_arg_update; @@ -140,27 +142,27 @@ static void test_fake_resolver() { grpc_combiner_scheduler(combiner)); // Set updated resolver results and trigger a second resolution. - grpc_fake_resolver_response_generator_set_response(response_generator, - results_update); - grpc_resolver_next_locked(resolver, &on_res_arg_update.resolver_result, - on_resolution); - grpc_core::ExecCtx::Get()->Flush(); + grpc_fake_resolver_response_generator_set_response( + &exec_ctx, response_generator, results_update); + grpc_resolver_next_locked(&exec_ctx, resolver, + &on_res_arg_update.resolver_result, on_resolution); + grpc_exec_ctx_flush(&exec_ctx); GPR_ASSERT(gpr_event_wait(&on_res_arg_update.ev, grpc_timeout_seconds_to_deadline(5)) != nullptr); // Requesting a new resolution without re-senting the response shouldn't // trigger the resolution callback. memset(&on_res_arg, 0, sizeof(on_res_arg)); - grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result, + grpc_resolver_next_locked(&exec_ctx, resolver, &on_res_arg.resolver_result, on_resolution); - grpc_core::ExecCtx::Get()->Flush(); + grpc_exec_ctx_flush(&exec_ctx); GPR_ASSERT(gpr_event_wait(&on_res_arg.ev, grpc_timeout_milliseconds_to_deadline(100)) == nullptr); - GRPC_COMBINER_UNREF(combiner, "test_fake_resolver"); - GRPC_RESOLVER_UNREF(resolver, "test_fake_resolver"); - + GRPC_COMBINER_UNREF(&exec_ctx, combiner, "test_fake_resolver"); + GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test_fake_resolver"); + grpc_exec_ctx_finish(&exec_ctx); grpc_fake_resolver_response_generator_unref(response_generator); } diff --git a/test/core/client_channel/resolvers/sockaddr_resolver_test.cc b/test/core/client_channel/resolvers/sockaddr_resolver_test.cc index 4d16a77924..dfa2d12b5e 100644 --- a/test/core/client_channel/resolvers/sockaddr_resolver_test.cc +++ b/test/core/client_channel/resolvers/sockaddr_resolver_test.cc @@ -35,14 +35,14 @@ typedef struct on_resolution_arg { grpc_channel_args* resolver_result; } on_resolution_arg; -void on_resolution_cb(void* arg, grpc_error* error) { +void on_resolution_cb(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { on_resolution_arg* res = static_cast<on_resolution_arg*>(arg); - grpc_channel_args_destroy(res->resolver_result); + grpc_channel_args_destroy(exec_ctx, res->resolver_result); } static void test_succeeds(grpc_resolver_factory* factory, const char* string) { - grpc_core::ExecCtx exec_ctx; - grpc_uri* uri = grpc_uri_parse(string, 0); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_uri* uri = grpc_uri_parse(&exec_ctx, string, 0); grpc_resolver_args args; grpc_resolver* resolver; gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", string, @@ -51,7 +51,7 @@ static void test_succeeds(grpc_resolver_factory* factory, const char* string) { memset(&args, 0, sizeof(args)); args.uri = uri; args.combiner = g_combiner; - resolver = grpc_resolver_factory_create_resolver(factory, &args); + resolver = grpc_resolver_factory_create_resolver(&exec_ctx, factory, &args); GPR_ASSERT(resolver != nullptr); on_resolution_arg on_res_arg; @@ -60,16 +60,16 @@ static void test_succeeds(grpc_resolver_factory* factory, const char* string) { grpc_closure* on_resolution = GRPC_CLOSURE_CREATE( on_resolution_cb, &on_res_arg, grpc_schedule_on_exec_ctx); - grpc_resolver_next_locked(resolver, &on_res_arg.resolver_result, + grpc_resolver_next_locked(&exec_ctx, resolver, &on_res_arg.resolver_result, on_resolution); - GRPC_RESOLVER_UNREF(resolver, "test_succeeds"); - + GRPC_RESOLVER_UNREF(&exec_ctx, resolver, "test_succeeds"); + grpc_exec_ctx_finish(&exec_ctx); grpc_uri_destroy(uri); } static void test_fails(grpc_resolver_factory* factory, const char* string) { - grpc_core::ExecCtx exec_ctx; - grpc_uri* uri = grpc_uri_parse(string, 0); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_uri* uri = grpc_uri_parse(&exec_ctx, string, 0); grpc_resolver_args args; grpc_resolver* resolver; gpr_log(GPR_DEBUG, "test: '%s' should be invalid for '%s'", string, @@ -78,9 +78,10 @@ static void test_fails(grpc_resolver_factory* factory, const char* string) { memset(&args, 0, sizeof(args)); args.uri = uri; args.combiner = g_combiner; - resolver = grpc_resolver_factory_create_resolver(factory, &args); + resolver = grpc_resolver_factory_create_resolver(&exec_ctx, factory, &args); GPR_ASSERT(resolver == nullptr); grpc_uri_destroy(uri); + grpc_exec_ctx_finish(&exec_ctx); } int main(int argc, char** argv) { @@ -111,8 +112,9 @@ int main(int argc, char** argv) { grpc_resolver_factory_unref(ipv6); { - grpc_core::ExecCtx exec_ctx; - GRPC_COMBINER_UNREF(g_combiner, "test"); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + GRPC_COMBINER_UNREF(&exec_ctx, g_combiner, "test"); + grpc_exec_ctx_finish(&exec_ctx); } grpc_shutdown(); |