From ca950fffaae6a0728f5ca23383c228d11986b754 Mon Sep 17 00:00:00 2001 From: XieHan Date: Sat, 30 Oct 2021 17:36:58 +0800 Subject: [PATCH] fix test case. --- src/nameservice/WFServiceGovernance.cc | 33 ++++++++------------------ test/upstream_unittest.cc | 2 ++ 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/nameservice/WFServiceGovernance.cc b/src/nameservice/WFServiceGovernance.cc index d62f2f13..364108ff 100644 --- a/src/nameservice/WFServiceGovernance.cc +++ b/src/nameservice/WFServiceGovernance.cc @@ -66,33 +66,19 @@ public: } }; -static bool copy_host_port(ParsedURI& uri, const EndpointAddress *addr) +static void copy_host_port(ParsedURI& uri, const EndpointAddress *addr) { - char *host = NULL; - char *port = NULL; - - if (!addr->host.empty()) + if (addr->host != uri.host) { - host = strdup(addr->host.c_str()); - if (!host) - return false; + free(uri.host); + uri.host = strdup(addr->host.c_str()); } - if (!addr->port.empty()) + if (addr->port != uri.port) { - port = strdup(addr->port.c_str()); - if (!port) - { - free(host); - return false; - } free(uri.port); - uri.port = port; + uri.port = strdup(addr->port.c_str()); } - - free(uri.host); - uri.host = host; - return true; } EndpointAddress::EndpointAddress(const std::string& address, @@ -128,8 +114,7 @@ WFRouterTask *WFServiceGovernance::create_router_task(const struct WFNSParams *p EndpointAddress *addr; WFRouterTask *task; - if (this->select(params->uri, tracing, &addr) && - copy_host_port(params->uri, addr)) + if (this->select(params->uri, tracing, &addr)) { WFDnsResolver *resolver = WFGlobal::get_dns_resolver(); unsigned int dns_ttl_default = addr->params->dns_ttl_default; @@ -137,6 +122,8 @@ WFRouterTask *WFServiceGovernance::create_router_task(const struct WFNSParams *p const struct EndpointParams *endpoint_params = &addr->params->endpoint_params; int dns_cache_level = params->retry_times == 0 ? DNS_CACHE_LEVEL_2 : DNS_CACHE_LEVEL_1; + + copy_host_port(params->uri, addr); task = resolver->create(params, dns_cache_level, dns_ttl_default, dns_ttl_min, endpoint_params, std::move(callback)); @@ -340,7 +327,7 @@ bool WFServiceGovernance::select(const ParsedURI& uri, WFNSTracing *tracing, if (select_addr) { *addr = select_addr; - ++(*addr)->ref; + ++select_addr->ref; } pthread_rwlock_unlock(&this->rwlock); diff --git a/test/upstream_unittest.cc b/test/upstream_unittest.cc index 05835159..6a544faa 100644 --- a/test/upstream_unittest.cc +++ b/test/upstream_unittest.cc @@ -224,6 +224,7 @@ TEST(upstream_unittest, AddAndRemove) wait_group.wait(); EXPECT_TRUE(http_server1.start("127.0.0.1", 8001) == 0) << "http server start failed"; + ns->del_policy(name.c_str()); } TEST(upstream_unittest, FuseAndRecover) @@ -285,6 +286,7 @@ TEST(upstream_unittest, FuseAndRecover) series->start(); wait_group.wait(); + ns->del_policy("test_policy"); } TEST(upstream_unittest, TryAnother)