diff options
author | 2017-12-08 13:03:05 -0800 | |
---|---|---|
committer | 2017-12-08 13:56:39 -0800 | |
commit | 280281fd4dcef2f4958185cd73b62d70df6f1767 (patch) | |
tree | 32c4c152bbf61e64f9946cb2a316af90124fcd3a /test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc | |
parent | a77fb7dc6792a48edc30100482032844c56feedc (diff) | |
parent | 94e676e10f8c739289924b8458a246699e3623ce (diff) |
Merge branch 'master' of https://github.com/grpc/grpc into flow-control-part4
Diffstat (limited to 'test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc')
-rw-r--r-- | test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc | 85 |
1 files changed, 40 insertions, 45 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 dcf315eba5..18a795fbcb 100644 --- a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc +++ b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc @@ -35,8 +35,7 @@ static gpr_mu g_mu; static bool g_fail_resolution = true; static grpc_combiner* g_combiner; -static void my_resolve_address(grpc_exec_ctx* exec_ctx, const char* addr, - const char* default_port, +static void my_resolve_address(const char* addr, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addrs) { @@ -55,13 +54,13 @@ static void my_resolve_address(grpc_exec_ctx* exec_ctx, const char* addr, gpr_malloc(sizeof(*(*addrs)->addrs))); (*addrs)->addrs[0].len = 123; } - GRPC_CLOSURE_SCHED(exec_ctx, on_done, error); + GRPC_CLOSURE_SCHED(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, + 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)); @@ -76,27 +75,26 @@ static grpc_ares_request* my_dns_lookup_ares( grpc_lb_addresses_set_address(*lb_addrs, 0, nullptr, 0, false, nullptr, nullptr); } - GRPC_CLOSURE_SCHED(exec_ctx, on_done, error); + GRPC_CLOSURE_SCHED(on_done, error); return nullptr; } -static grpc_resolver* create_resolver(grpc_exec_ctx* exec_ctx, - const char* name) { +static grpc_resolver* create_resolver(const char* name) { grpc_resolver_factory* factory = grpc_resolver_factory_lookup("dns"); - grpc_uri* uri = grpc_uri_parse(exec_ctx, name, 0); + grpc_uri* uri = grpc_uri_parse(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(exec_ctx, factory, &args); + grpc_resolver_factory_create_resolver(factory, &args); grpc_resolver_factory_unref(factory); grpc_uri_destroy(uri); return resolver; } -static void on_done(grpc_exec_ctx* exec_ctx, void* ev, grpc_error* error) { +static void on_done(void* ev, grpc_error* error) { gpr_event_set((gpr_event*)ev, (void*)1); } @@ -107,9 +105,8 @@ 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_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_timer_check(&exec_ctx, nullptr); - grpc_exec_ctx_finish(&exec_ctx); + grpc_core::ExecCtx exec_ctx; + grpc_timer_check(nullptr); } return false; } @@ -120,16 +117,14 @@ typedef struct next_args { grpc_closure* on_complete; } next_args; -static void call_resolver_next_now_lock_taken(grpc_exec_ctx* exec_ctx, - void* arg, +static void call_resolver_next_now_lock_taken(void* arg, grpc_error* error_unused) { next_args* a = static_cast<next_args*>(arg); - grpc_resolver_next_locked(exec_ctx, a->resolver, a->result, a->on_complete); + grpc_resolver_next_locked(a->resolver, a->result, a->on_complete); gpr_free(a); } -static void call_resolver_next_after_locking(grpc_exec_ctx* exec_ctx, - grpc_resolver* resolver, +static void call_resolver_next_after_locking(grpc_resolver* resolver, grpc_channel_args** result, grpc_closure* on_complete) { next_args* a = static_cast<next_args*>(gpr_malloc(sizeof(*a))); @@ -137,7 +132,6 @@ static void call_resolver_next_after_locking(grpc_exec_ctx* exec_ctx, 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); @@ -153,30 +147,31 @@ int main(int argc, char** argv) { 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; - 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_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_shutdown(); gpr_mu_destroy(&g_mu); |