Loading tests/resolv_integration_test.cpp +71 −0 Original line number Original line Diff line number Diff line Loading @@ -1399,6 +1399,77 @@ TEST_F(ResolverTest, ResolverStats) { EXPECT_EQ(1, res_stats[2].successes); EXPECT_EQ(1, res_stats[2].successes); } } TEST_F(ResolverTest, AlwaysUseLatestSetupParamsInLookups) { constexpr char listen_addr1[] = "127.0.0.3"; constexpr char listen_addr2[] = "255.255.255.255"; constexpr char listen_addr3[] = "127.0.0.4"; constexpr char hostname[] = "hello"; constexpr char fqdn_with_search_domain[] = "hello.domain2.com."; test::DNSResponder dns1(listen_addr1, test::kDefaultListenService, static_cast<ns_rcode>(-1)); dns1.setResponseProbability(0.0); ASSERT_TRUE(dns1.startServer()); test::DNSResponder dns3(listen_addr3); StartDns(dns3, {{fqdn_with_search_domain, ns_type::ns_t_a, "1.2.3.4"}}); ResolverParamsParcel parcel = DnsResponderClient::GetDefaultResolverParamsParcel(); parcel.tlsServers.clear(); parcel.servers = {listen_addr1, listen_addr2}; parcel.domains = {"domain1.com", "domain2.com"}; ASSERT_TRUE(mDnsClient.SetResolversFromParcel(parcel)); // Expect the things happening in t1: // 1. The lookup starts using the first domain for query. It sends queries to the populated // nameserver list {listen_addr1, listen_addr2} for the hostname "hello.domain1.com". // 2. A different list of nameservers is updated to the resolver. Revision ID is incremented. // 3. The query for the hostname times out. The lookup fails to add the timeout record to the // the stats because of the unmatched revision ID. // 4. The lookup starts using the second domain for query. It sends queries to the populated // nameserver list {listen_addr3, listen_addr1, listen_addr2} for another hostname // "hello.domain2.com". // 5. The lookup gets the answer and updates a success record to the stats. std::thread t1([&hostname]() { const addrinfo hints = {.ai_family = AF_INET, .ai_socktype = SOCK_DGRAM}; ScopedAddrinfo result = safe_getaddrinfo(hostname, nullptr, &hints); EXPECT_NE(result.get(), nullptr); EXPECT_EQ(ToString(result), "1.2.3.4"); }); // Wait for t1 to start the step 1. while (dns1.queries().size() == 0) { usleep(1000); } // Update the resolver with three nameservers. This will increment the revision ID. parcel.servers = {listen_addr3, listen_addr1, listen_addr2}; ASSERT_TRUE(mDnsClient.SetResolversFromParcel(parcel)); t1.join(); EXPECT_EQ(0U, GetNumQueriesForType(dns3, ns_type::ns_t_aaaa, fqdn_with_search_domain)); EXPECT_EQ(1U, GetNumQueriesForType(dns3, ns_type::ns_t_a, fqdn_with_search_domain)); std::vector<std::string> res_servers; std::vector<std::string> res_domains; std::vector<std::string> res_tls_servers; res_params res_params; std::vector<ResolverStats> res_stats; int wait_for_pending_req_timeout_count; ASSERT_TRUE(DnsResponderClient::GetResolverInfo( mDnsClient.resolvService(), TEST_NETID, &res_servers, &res_domains, &res_tls_servers, &res_params, &res_stats, &wait_for_pending_req_timeout_count)); EXPECT_EQ(res_stats[0].successes, 1); EXPECT_EQ(res_stats[0].timeouts, 0); EXPECT_EQ(res_stats[0].internal_errors, 0); EXPECT_EQ(res_stats[1].successes, 0); EXPECT_EQ(res_stats[1].timeouts, 0); EXPECT_EQ(res_stats[1].internal_errors, 0); EXPECT_EQ(res_stats[2].successes, 0); EXPECT_EQ(res_stats[2].timeouts, 0); EXPECT_EQ(res_stats[2].internal_errors, 0); EXPECT_EQ(res_servers, parcel.servers); } // Test what happens if the specified TLS server is nonexistent. // Test what happens if the specified TLS server is nonexistent. TEST_F(ResolverTest, GetHostByName_TlsMissing) { TEST_F(ResolverTest, GetHostByName_TlsMissing) { constexpr char listen_addr[] = "127.0.0.3"; constexpr char listen_addr[] = "127.0.0.3"; Loading Loading
tests/resolv_integration_test.cpp +71 −0 Original line number Original line Diff line number Diff line Loading @@ -1399,6 +1399,77 @@ TEST_F(ResolverTest, ResolverStats) { EXPECT_EQ(1, res_stats[2].successes); EXPECT_EQ(1, res_stats[2].successes); } } TEST_F(ResolverTest, AlwaysUseLatestSetupParamsInLookups) { constexpr char listen_addr1[] = "127.0.0.3"; constexpr char listen_addr2[] = "255.255.255.255"; constexpr char listen_addr3[] = "127.0.0.4"; constexpr char hostname[] = "hello"; constexpr char fqdn_with_search_domain[] = "hello.domain2.com."; test::DNSResponder dns1(listen_addr1, test::kDefaultListenService, static_cast<ns_rcode>(-1)); dns1.setResponseProbability(0.0); ASSERT_TRUE(dns1.startServer()); test::DNSResponder dns3(listen_addr3); StartDns(dns3, {{fqdn_with_search_domain, ns_type::ns_t_a, "1.2.3.4"}}); ResolverParamsParcel parcel = DnsResponderClient::GetDefaultResolverParamsParcel(); parcel.tlsServers.clear(); parcel.servers = {listen_addr1, listen_addr2}; parcel.domains = {"domain1.com", "domain2.com"}; ASSERT_TRUE(mDnsClient.SetResolversFromParcel(parcel)); // Expect the things happening in t1: // 1. The lookup starts using the first domain for query. It sends queries to the populated // nameserver list {listen_addr1, listen_addr2} for the hostname "hello.domain1.com". // 2. A different list of nameservers is updated to the resolver. Revision ID is incremented. // 3. The query for the hostname times out. The lookup fails to add the timeout record to the // the stats because of the unmatched revision ID. // 4. The lookup starts using the second domain for query. It sends queries to the populated // nameserver list {listen_addr3, listen_addr1, listen_addr2} for another hostname // "hello.domain2.com". // 5. The lookup gets the answer and updates a success record to the stats. std::thread t1([&hostname]() { const addrinfo hints = {.ai_family = AF_INET, .ai_socktype = SOCK_DGRAM}; ScopedAddrinfo result = safe_getaddrinfo(hostname, nullptr, &hints); EXPECT_NE(result.get(), nullptr); EXPECT_EQ(ToString(result), "1.2.3.4"); }); // Wait for t1 to start the step 1. while (dns1.queries().size() == 0) { usleep(1000); } // Update the resolver with three nameservers. This will increment the revision ID. parcel.servers = {listen_addr3, listen_addr1, listen_addr2}; ASSERT_TRUE(mDnsClient.SetResolversFromParcel(parcel)); t1.join(); EXPECT_EQ(0U, GetNumQueriesForType(dns3, ns_type::ns_t_aaaa, fqdn_with_search_domain)); EXPECT_EQ(1U, GetNumQueriesForType(dns3, ns_type::ns_t_a, fqdn_with_search_domain)); std::vector<std::string> res_servers; std::vector<std::string> res_domains; std::vector<std::string> res_tls_servers; res_params res_params; std::vector<ResolverStats> res_stats; int wait_for_pending_req_timeout_count; ASSERT_TRUE(DnsResponderClient::GetResolverInfo( mDnsClient.resolvService(), TEST_NETID, &res_servers, &res_domains, &res_tls_servers, &res_params, &res_stats, &wait_for_pending_req_timeout_count)); EXPECT_EQ(res_stats[0].successes, 1); EXPECT_EQ(res_stats[0].timeouts, 0); EXPECT_EQ(res_stats[0].internal_errors, 0); EXPECT_EQ(res_stats[1].successes, 0); EXPECT_EQ(res_stats[1].timeouts, 0); EXPECT_EQ(res_stats[1].internal_errors, 0); EXPECT_EQ(res_stats[2].successes, 0); EXPECT_EQ(res_stats[2].timeouts, 0); EXPECT_EQ(res_stats[2].internal_errors, 0); EXPECT_EQ(res_servers, parcel.servers); } // Test what happens if the specified TLS server is nonexistent. // Test what happens if the specified TLS server is nonexistent. TEST_F(ResolverTest, GetHostByName_TlsMissing) { TEST_F(ResolverTest, GetHostByName_TlsMissing) { constexpr char listen_addr[] = "127.0.0.3"; constexpr char listen_addr[] = "127.0.0.3"; Loading