MCPcopy Create free account
hub / github.com/rthalley/dnspython / test_cache_stats

Method test_cache_stats

tests/test_resolver.py:481–514  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

479 self.assertTrue(on_lru_list(cache, key, answer2))
480
481 def test_cache_stats(self):
482 caches = [dns.resolver.Cache(), dns.resolver.LRUCache(4)]
483 key1 = (dns.name.from_text("key1."), dns.rdatatype.A, dns.rdataclass.IN)
484 key2 = (dns.name.from_text("key2."), dns.rdatatype.A, dns.rdataclass.IN)
485 for cache in caches:
486 answer1 = FakeAnswer(time.time() + 10)
487 answer2 = FakeAnswer(10) # expired!
488 a = cache.get(key1)
489 self.assertIsNone(a)
490 self.assertEqual(cache.hits(), 0)
491 self.assertEqual(cache.misses(), 1)
492 if isinstance(cache, dns.resolver.LRUCache):
493 self.assertEqual(cache.get_hits_for_key(key1), 0)
494 cache.put(key1, answer1)
495 a = cache.get(key1)
496 self.assertIs(a, answer1)
497 self.assertEqual(cache.hits(), 1)
498 self.assertEqual(cache.misses(), 1)
499 if isinstance(cache, dns.resolver.LRUCache):
500 self.assertEqual(cache.get_hits_for_key(key1), 1)
501 cache.put(key2, answer2)
502 a = cache.get(key2)
503 self.assertIsNone(a)
504 self.assertEqual(cache.hits(), 1)
505 self.assertEqual(cache.misses(), 2)
506 if isinstance(cache, dns.resolver.LRUCache):
507 self.assertEqual(cache.get_hits_for_key(key2), 0)
508 stats = cache.get_statistics_snapshot()
509 self.assertEqual(stats.hits, 1)
510 self.assertEqual(stats.misses, 2)
511 cache.reset_statistics()
512 stats = cache.get_statistics_snapshot()
513 self.assertEqual(stats.hits, 0)
514 self.assertEqual(stats.misses, 0)
515
516 def testEmptyAnswerSection(self):
517 # TODO: dangling_cname_0_message_text was the only sample message

Callers

nothing calls this directly

Calls 10

FakeAnswerClass · 0.85
timeMethod · 0.80
hitsMethod · 0.80
missesMethod · 0.80
get_hits_for_keyMethod · 0.80
reset_statisticsMethod · 0.80
from_textMethod · 0.45
getMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected