Skip to content

Commit

Permalink
Fix unittest for default resovler
Browse files Browse the repository at this point in the history
  • Loading branch information
HanLee13 committed Dec 22, 2023
1 parent 9107c43 commit 450dd57
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions net/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,9 +714,9 @@ TEST(utils, resolver) {
DEFER(delete resolver);
net::IPAddr localhost("127.0.0.1");
net::IPAddr addr = resolver->resolve("localhost");
EXPECT_EQ(localhost.to_nl(), addr.to_nl());
if (addr.is_ipv4()) EXPECT_EQ(localhost.to_nl(), addr.to_nl());
auto func = [&](net::IPAddr addr_){
EXPECT_EQ(localhost.to_nl(), addr_.to_nl());
if (addr_.is_ipv4()) EXPECT_EQ(localhost.to_nl(), addr_.to_nl());
};
resolver->resolve("localhost", func);
resolver->discard_cache("non-exist-host.com");
Expand Down
7 changes: 6 additions & 1 deletion net/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,12 @@ class DefaultResolver : public Resolver {
public:
DefaultResolver(uint64_t cache_ttl, uint64_t resolve_timeout)
: dnscache_(cache_ttl), resolve_timeout_(resolve_timeout) {}
~DefaultResolver() { dnscache_.clear(); }
~DefaultResolver() {
for (auto it : dnscache_) {
((IPAddrList*)it->_obj)->delete_all();
}
dnscache_.clear();
}

IPAddr resolve(const char *host) override {
auto ctr = [&]() -> IPAddrList* {
Expand Down

0 comments on commit 450dd57

Please sign in to comment.