ϪfrdZddlZddlmZddlmZmZddlmZm Z ddl m Z Gdde jZ y) z# Tests for L{twisted.names.cache}. N) verifyClass) interfacestask)cachedns)unittestc4eZdZdZdZdZdZdZdZdZ y) CachingTestsz+ Tests for L{cache.CacheResolver}. cTttjtjy)zK L{cache.CacheResolver} implements L{interfaces.IResolver} N)rr IResolverr CacheResolver)selfs ?/usr/lib/python3/dist-packages/twisted/names/test/test_cache.pytest_interfacezCachingTests.test_interfaces J((%*=*=>ctjtjdtjtj t j gggffi}|jdj|jgggfS)N example.comnametypecls) rr rQueryMXINtimelookupMailExchange addCallback assertEqual)rcs r test_lookupzCachingTests.test_lookupsx    ~CFFGIIKRLJ  ##N3??   r2rl  rc Vtjdtjtjdtjddgtjdtjtjdtjddgtjdtjtjdtjddgf}t j }tjdtjtj}tj||j|fi|}|jd|j||j|j|jdtjS)z Cache entries passed into L{cache.CacheResolver.__init__} get cancelled just like entries added with cacheResult r< 127.0.0.12(rreactor)rRRHeaderArRecord_ArClockrrr secondsadvance assertNotIn assertFailure lookupAddress DomainError)rrclockqueryrs rtest_constructorExpiresz$CachingTests.test_constructorExpires*s* "CEE3662s||KQS7T   "CEE3662s||KQS7T   "CEE3662s||KQS7T  $  ~CEEsvvF   !(< =u M  b (!!!//."A3??SSrc tjdtjtjdtjddgtjdtjtjdtjddgtjdtjtjdtjddgf}t j }tj|}|jtjdtjtj||jdfd }|jdj|S) z When a cache lookup finds a cached entry from 1 second ago, it is returned with a TTL of original TTL minus the elapsed 1 second. rr"r#r$r%r&rc*j|ddjdj|ddjdj|ddjdj|ddjjdy)Nr;r71'r)rttlr)resultrs rcbLookupz0CachingTests.test_normalLookup..cbLookupls   VAYq\--r 2   VAYq\--r 2   VAYq\--r 2   VAYq\..33^ Dr)rr(r)rr*rr+rr cacheResultrr-r0r)rr2r3rr?s` rtest_normalLookupzCachingTests.test_normalLookupNs "CEE3662s||KQS7T   "CEE3662s||KQS7T   "CEE3662s||KQS7T  $     . cii^#%%SVVLaP a E ~.::8DDrc Ttjdtjtjdtjddgtjdtjtjdtjddgtjdtjtjdtjddgf}t j }tj|}tjdtjtj}|j|||jd|j||j|j|jdtjS)zW Once the TTL has been exceeded, the result is removed from the cache. rr"r#r$r%r&r)rr(r)rr*rr+rr rr@r-r.r/r0r1)rr2r3rr4s rtest_cachedResultExpiresz%CachingTests.test_cachedResultExpirests$  "CEE3662s||KQS7T   "CEE3662s||KQS7T   "CEE3662s||KQS7T  $     . ~CEEsvvF eQ b (!!!//."A3??SSrc *tjdtjtjdtjddgtjdtjtjdtjddgtjdtjtjdtjddgf}t j }d|_tjtjdtjtj|j|fi|}|jd |j|jdtjS) z When the cache is queried exactly as the cached entry should expire but before it has actually been cleared, the cache does not return the expired entry. rr"r#r$r%cy)N)argskwargss rz4CachingTests.test_expiredTTLLookup..srrr&g N@)rr(r)rr*rr+ callLaterrr rr,r-r/r0r1)rr2r3rs rtest_expiredTTLLookupz"CachingTests.test_expiredTTLLookups% "CEE3662s||KQS7T   "CEE3662s||KQS7T   "CEE3662s||KQS7T  $ 6    ~CEEsvvFMMOI     d!!!//."A3??SSrN) __name__ __module__ __qualname____doc__rr r5rArCrKrFrrr r s,?  "TH$EL TD(Trr )rOrzope.interface.verifyrtwisted.internetrr twisted.namesrr twisted.trialrTestCaser rFrrrUs1  --$"lT8$$lTr