test: Separate live tests from SetServers* tests (#299)

Before this change, SetServers, SetServersPorts and SetServersCSV
contained test cases trying to make DNS queries with the google.com
hostname, which requires Internet connectivity. Tests with that
requirement should be defined in the ares-test-live.cc file and contain
"Live" prefix to filter them out with `--gtest_filter=-*.Live*` on
machines without Internet connectivity.

Fix By: Michal Rostecki (@mrostecki)
pull/304/head
Michal Rostecki 5 years ago committed by GitHub
parent b9eb3a0cfe
commit d30999dc89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 48
      test/ares-test-live.cc
  2. 19
      test/ares-test-misc.cc

@ -693,6 +693,54 @@ TEST_F(DefaultChannelTest, VerifySocketFunctionCallback) {
}
TEST_F(DefaultChannelTest, LiveSetServers) {
struct ares_addr_node server1;
struct ares_addr_node server2;
server1.next = &server2;
server1.family = AF_INET;
server1.addr.addr4.s_addr = htonl(0x01020304);
server2.next = nullptr;
server2.family = AF_INET;
server2.addr.addr4.s_addr = htonl(0x02030405);
// Change not allowed while request is pending
HostResult result;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
EXPECT_EQ(ARES_ENOTIMP, ares_set_servers(channel_, &server1));
ares_cancel(channel_);
}
TEST_F(DefaultChannelTest, LiveSetServersPorts) {
struct ares_addr_port_node server1;
struct ares_addr_port_node server2;
server1.next = &server2;
server1.family = AF_INET;
server1.addr.addr4.s_addr = htonl(0x01020304);
server1.udp_port = 111;
server1.tcp_port = 111;
server2.next = nullptr;
server2.family = AF_INET;
server2.addr.addr4.s_addr = htonl(0x02030405);
server2.udp_port = 0;
server2.tcp_port = 0;;
EXPECT_EQ(ARES_ENODATA, ares_set_servers_ports(nullptr, &server1));
// Change not allowed while request is pending
HostResult result;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
EXPECT_EQ(ARES_ENOTIMP, ares_set_servers_ports(channel_, &server1));
ares_cancel(channel_);
}
TEST_F(DefaultChannelTest, LiveSetServersCSV) {
// Change not allowed while request is pending
HostResult result;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
EXPECT_EQ(ARES_ENOTIMP, ares_set_servers_csv(channel_, "1.2.3.4,2.3.4.5"));
EXPECT_EQ(ARES_ENOTIMP, ares_set_servers_ports_csv(channel_, "1.2.3.4:56,2.3.4.5:67"));
ares_cancel(channel_);
}
} // namespace test
} // namespace ares

@ -45,12 +45,6 @@ TEST_F(DefaultChannelTest, SetServers) {
EXPECT_EQ(ARES_SUCCESS, ares_set_servers(channel_, &server1));
std::vector<std::string> expected = {"1.2.3.4", "2.3.4.5"};
EXPECT_EQ(expected, GetNameServers(channel_));
// Change not allowed while request is pending
HostResult result;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
EXPECT_EQ(ARES_ENOTIMP, ares_set_servers(channel_, &server1));
ares_cancel(channel_);
}
TEST_F(DefaultChannelTest, SetServersPorts) {
@ -75,12 +69,6 @@ TEST_F(DefaultChannelTest, SetServersPorts) {
EXPECT_EQ(ARES_SUCCESS, ares_set_servers_ports(channel_, &server1));
std::vector<std::string> expected = {"1.2.3.4:111", "2.3.4.5"};
EXPECT_EQ(expected, GetNameServers(channel_));
// Change not allowed while request is pending
HostResult result;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
EXPECT_EQ(ARES_ENOTIMP, ares_set_servers_ports(channel_, &server1));
ares_cancel(channel_);
}
TEST_F(DefaultChannelTest, SetServersCSV) {
@ -108,13 +96,6 @@ TEST_F(DefaultChannelTest, SetServersCSV) {
std::vector<std::string> expected2 = {"1.2.3.4:54", "[0102:0304:0506:0708:0910:1112:1314:1516]:80", "2.3.4.5:55"};
EXPECT_EQ(expected2, GetNameServers(channel_));
// Change not allowed while request is pending
HostResult result;
ares_gethostbyname(channel_, "www.google.com.", AF_INET, HostCallback, &result);
EXPECT_EQ(ARES_ENOTIMP, ares_set_servers_csv(channel_, "1.2.3.4,2.3.4.5"));
EXPECT_EQ(ARES_ENOTIMP, ares_set_servers_ports_csv(channel_, "1.2.3.4:56,2.3.4.5:67"));
ares_cancel(channel_);
// Should survive duplication
ares_channel channel2;
EXPECT_EQ(ARES_SUCCESS, ares_dup(&channel2, channel_));

Loading…
Cancel
Save