// constants for master
address name_server = address::from_string("127.0.0.1");
-int resolved_ip_ttl_threshold = 3;
+int resolved_ip_ttl_threshold = 5;
+uint32_t min_time_between_resolves = 3; // should be < resolved_ip_ttl_threshold
int max_address_resolution_attempts = 2;
std::string cache_file = DnsCache::DoNotUseCacheFile;
// DNS Cache
DnsCacheItem cache_temp = DnsCacheItem(
- new DnsCache(IoService, cache_file) );
+ new DnsCache(IoService, cache_file, min_time_between_resolves) );
cache_temp.swap( Cache );
cache_temp.reset();
fill_cache();
Cache->update("cname3.test", Cname("cname2.test", 37) );
}
- {
+ { // for cache_outdated_test
HostAddressVec ips;
ips.push_back( HostAddress( address::from_string("192.168.42.4"),
0 ) );
Cname("host_outdated.test", resolved_ip_ttl_threshold+1));
}
+ { // for cache_ttl_below_thresh_test
+ // TTLs < min_time_between_resolves should be corrected
+ HostAddressVec ips;
+ ips.push_back( HostAddress( address::from_string("192.128.42.8"),
+ 1 ) );
+ Cache->update("host_ttl_below_thresh.test", ips);
+
+ Cache->update( "cname_ttl_below_thresh.test",
+ Cname("host_ttl_below_thresh.test", 2) );
+ }
+
BOOST_TEST_MESSAGE( "Done filling cache." );
}
BOOST_AUTO_TEST_CASE( cache_retrieve_ip1 )
{
HostAddressVec ips = Cache->get_ips("host1.test");
- BOOST_CHECK_EQUAL( ips.size(), 1 );
+ BOOST_REQUIRE_EQUAL( ips.size(), 1 );
HostAddress ip = ips.front();
BOOST_CHECK( ip.is_valid() );
BOOST_CHECK_EQUAL( ip.get_ip().to_string(), "192.168.42.1" );
{
// should get IP from host1 but ttl from cname since is smaller
HostAddressVec ips = Cache->get_ips_recursive("cname.test");
- BOOST_CHECK_EQUAL( ips.size(), 1 );
+ BOOST_REQUIRE_EQUAL( ips.size(), 1 );
HostAddress ip = ips.front();
BOOST_CHECK( ip.is_valid() );
BOOST_CHECK_EQUAL( ip.get_ip().to_string(), "192.168.42.1" );
{
// should get IP from host1 but ttl from cname2 since is smaller
HostAddressVec ips = Cache->get_ips_recursive("cname3.test");
- BOOST_CHECK_EQUAL( ips.size(), 1 );
+ BOOST_REQUIRE_EQUAL( ips.size(), 1 );
HostAddress ip = ips.front();
BOOST_CHECK( ip.is_valid() );
BOOST_CHECK_EQUAL( ip.get_ip().to_string(), "192.168.42.1" );
std::stringstream file_name;
file_name << DATA_DIR_STRING << "/" << "dns_cache_example.xml";
BOOST_TEST_MESSAGE( "loading cache from file " << file_name.str() );
- DnsCache loaded_cache( IoService, file_name.str() );
+ DnsCache loaded_cache( IoService,
+ file_name.str(),
+ min_time_between_resolves );
HostAddressVec ips = loaded_cache.get_ips("abc.xyz");
- BOOST_CHECK_EQUAL( ips.size(), 1 );
+ BOOST_REQUIRE_EQUAL( ips.size(), 1 );
HostAddress ip = ips.front();
BOOST_CHECK_EQUAL( ip.get_ip().to_string(), "11.22.33.44" );
BOOST_CHECK_EQUAL( ip.get_ttl().get_value(), 567 );
BOOST_CHECK_EQUAL( ips.size(), 1 );
}
+BOOST_AUTO_TEST_CASE( cache_ttl_below_thresh_test )
+{
+ // in fill_cache,
+ HostAddressVec ips = Cache->get_ips("host_ttl_below_thresh.test", false);
+ BOOST_REQUIRE_EQUAL( ips.size(), 1 );
+ HostAddress ip = ips.front();
+ BOOST_CHECK_EQUAL( ip.get_ttl().get_value(), min_time_between_resolves );
+ Cname cname = Cache->get_cname("cname_ttl_below_thresh.test", false);
+ BOOST_CHECK_EQUAL( cname.Ttl.get_value(), min_time_between_resolves );
+}
BOOST_AUTO_TEST_SUITE_END() // of TestDnsCache