Commit 1211ddcc authored by zhujiashun's avatar zhujiashun

fix_ut_brpc_baidu_com

parent 983b9970
......@@ -45,7 +45,7 @@ TEST_F(NamingServiceFilterTest, sanity) {
"10.128.0.1:1234 enable",
"10.129.0.1:1234",
"localhost:1234",
"brpc.baidu.com:1234"
"baidu.com:1234"
};
butil::TempFile tmp_file;
{
......
......@@ -50,6 +50,19 @@ DECLARE_int32(discovery_renew_interval_s);
} // brpc
namespace {
bool IsIPListEqual(const std::set<butil::ip_t>& s1, const std::set<butil::ip_t>& s2) {
if (s1.size() != s2.size()) {
return false;
}
for (auto it1 = s1.begin(), it2 = s2.begin(); it1 != s1.end(); ++it1, ++it2) {
if (*it1 != *it2) {
return false;
}
}
return true;
}
TEST(NamingServiceTest, sanity) {
std::vector<brpc::ServerNode> servers;
......@@ -59,32 +72,39 @@ TEST(NamingServiceTest, sanity) {
#endif
brpc::policy::DomainNamingService dns;
ASSERT_EQ(0, dns.GetServers("brpc.baidu.com:1234", &servers));
ASSERT_EQ(1u, servers.size());
ASSERT_EQ(0, dns.GetServers("baidu.com:1234", &servers));
ASSERT_EQ(2u, servers.size());
ASSERT_EQ(1234, servers[0].addr.port);
const butil::ip_t expected_ip = servers[0].addr.ip;
ASSERT_EQ(1234, servers[1].addr.port);
const std::set<butil::ip_t> expected_ips{servers[0].addr.ip, servers[1].addr.ip};
ASSERT_EQ(0, dns.GetServers("brpc.baidu.com", &servers));
ASSERT_EQ(1u, servers.size());
ASSERT_EQ(expected_ip, servers[0].addr.ip);
ASSERT_EQ(0, dns.GetServers("baidu.com", &servers));
ASSERT_EQ(2u, servers.size());
const std::set<butil::ip_t> ip_list1{servers[0].addr.ip, servers[1].addr.ip};
ASSERT_TRUE(IsIPListEqual(expected_ips, ip_list1));
ASSERT_EQ(80, servers[0].addr.port);
ASSERT_EQ(80, servers[1].addr.port);
ASSERT_EQ(0, dns.GetServers("brpc.baidu.com:1234/useless1/useless2", &servers));
ASSERT_EQ(1u, servers.size());
ASSERT_EQ(expected_ip, servers[0].addr.ip);
ASSERT_EQ(0, dns.GetServers("baidu.com:1234/useless1/useless2", &servers));
ASSERT_EQ(2u, servers.size());
const std::set<butil::ip_t> ip_list2{servers[0].addr.ip, servers[1].addr.ip};
ASSERT_TRUE(IsIPListEqual(expected_ips, ip_list2));
ASSERT_EQ(1234, servers[0].addr.port);
ASSERT_EQ(1234, servers[1].addr.port);
ASSERT_EQ(0, dns.GetServers("brpc.baidu.com/useless1/useless2", &servers));
ASSERT_EQ(1u, servers.size());
ASSERT_EQ(expected_ip, servers[0].addr.ip);
ASSERT_EQ(0, dns.GetServers("baidu.com/useless1/useless2", &servers));
ASSERT_EQ(2u, servers.size());
const std::set<butil::ip_t> ip_list3{servers[0].addr.ip, servers[1].addr.ip};
ASSERT_TRUE(IsIPListEqual(expected_ips, ip_list3));
ASSERT_EQ(80, servers[0].addr.port);
ASSERT_EQ(80, servers[1].addr.port);
const char *address_list[] = {
"10.127.0.1:1234",
"10.128.0.1:1234",
"10.129.0.1:1234",
"localhost:1234",
"brpc.baidu.com:1234"
"baidu.com:1234"
};
butil::TempFile tmp_file;
{
......@@ -126,9 +146,9 @@ TEST(NamingServiceTest, invalid_port) {
#endif
brpc::policy::DomainNamingService dns;
ASSERT_EQ(-1, dns.GetServers("brpc.baidu.com:", &servers));
ASSERT_EQ(-1, dns.GetServers("brpc.baidu.com:123a", &servers));
ASSERT_EQ(-1, dns.GetServers("brpc.baidu.com:99999", &servers));
ASSERT_EQ(-1, dns.GetServers("baidu.com:", &servers));
ASSERT_EQ(-1, dns.GetServers("baidu.com:123a", &servers));
ASSERT_EQ(-1, dns.GetServers("baidu.com:99999", &servers));
}
TEST(NamingServiceTest, wrong_name) {
......@@ -146,7 +166,7 @@ TEST(NamingServiceTest, wrong_name) {
"10.128.0.1:",
"10.128.0.1",
"localhost:1234",
"brpc.baidu.com:1234",
"baidu.com:1234",
"LOCAL:1234"
};
butil::TempFile tmp_file;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment