From 02ce860592586d52276e64b766a38990db7425e2 Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Tue, 27 Feb 2018 11:38:50 -0800 Subject: [PATCH] Add a flag to the resolver_component_test that permits extra addresses --- test/cpp/naming/resolver_component_test.cc | 32 ++++++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/test/cpp/naming/resolver_component_test.cc b/test/cpp/naming/resolver_component_test.cc index f4be064305c..bfdcd962386 100644 --- a/test/cpp/naming/resolver_component_test.cc +++ b/test/cpp/naming/resolver_component_test.cc @@ -65,6 +65,11 @@ DEFINE_string(expected_addrs, "", "List of expected backend or balancer addresses in the form " "',;,;...'. " "'is_balancer' should be bool, i.e. true or false."); +DEFINE_bool(allow_extra_addrs, false, + "Permit extra resolved addresses in the final list of " + "resolved addresses. This is useful in certain integration " + "test environments in which DNS responses are not fully " + "deterministic."); DEFINE_string(expected_chosen_service_config, "", "Expected service config json string that gets chosen (no " "whitespace). Empty for none."); @@ -240,9 +245,11 @@ void CheckResolverResultLocked(void* argsp, grpc_error* err) { GPR_ASSERT(channel_arg->type == GRPC_ARG_POINTER); grpc_lb_addresses* addresses = (grpc_lb_addresses*)channel_arg->value.pointer.p; - gpr_log(GPR_INFO, "num addrs found: %" PRIdPTR ". expected %" PRIdPTR, - addresses->num_addresses, args->expected_addrs.size()); - GPR_ASSERT(addresses->num_addresses == args->expected_addrs.size()); + gpr_log(GPR_INFO, + "num addrs found: %" PRIdPTR ". expected %" PRIdPTR + ". Allow extra addresses:%d.", + addresses->num_addresses, args->expected_addrs.size(), + FLAGS_allow_extra_addrs); std::vector found_lb_addrs; for (size_t i = 0; i < addresses->num_addresses; i++) { grpc_lb_address addr = addresses->addresses[i]; @@ -254,13 +261,20 @@ void CheckResolverResultLocked(void* argsp, grpc_error* err) { gpr_free(str); } if (args->expected_addrs.size() != found_lb_addrs.size()) { - gpr_log(GPR_DEBUG, - "found lb addrs size is: %" PRIdPTR - ". expected addrs size is %" PRIdPTR, - found_lb_addrs.size(), args->expected_addrs.size()); - abort(); + // Permit extra resolved addresses if "--allow_extra_addrs" was set. + if (!(FLAGS_allow_extra_addrs && + found_lb_addrs.size() > args->expected_addrs.size())) { + gpr_log(GPR_DEBUG, + "found lb addrs size is: %" PRIdPTR + ". expected addrs size is %" PRIdPTR ". --allow_extra_addrs=%d.", + found_lb_addrs.size(), args->expected_addrs.size(), + FLAGS_allow_extra_addrs); + abort(); + } + } + for (size_t i = 0; i < args->expected_addrs.size(); i++) { + EXPECT_THAT(found_lb_addrs, ::testing::Contains(args->expected_addrs[i])); } - EXPECT_THAT(args->expected_addrs, UnorderedElementsAreArray(found_lb_addrs)); CheckServiceConfigResultLocked(channel_args, args); if (args->expected_service_config_string == "") { CheckLBPolicyResultLocked(channel_args, args);