MCPcopy
hub / github.com/AdguardTeam/dnsproxy / setAndGetCache

Function setAndGetCache

proxy/cache_internal_test.go:616–651  ·  view source on GitHub ↗
(t *testing.T, c *cache, g *sync.WaitGroup, host, ip string)

Source from the content-addressed store, hash-verified

614}
615
616func setAndGetCache(t *testing.T, c *cache, g *sync.WaitGroup, host, ip string) {
617 defer g.Done()
618
619 ipAddr := net.ParseIP(ip)
620
621 req := (&dns.Msg{
622 MsgHdr: dns.MsgHdr{
623 Id: dns.Id(),
624 },
625 }).SetQuestion(host, dns.TypeA)
626
627 dnsMsg := (&dns.Msg{
628 MsgHdr: dns.MsgHdr{
629 Response: true,
630 },
631 Answer: []dns.RR{newRR(t, host, dns.TypeA, 1, ipAddr)},
632 }).SetQuestion(host, dns.TypeA)
633
634 c.set(req, dnsMsg, upstreamWithAddr, testLogger)
635
636 for range 2 {
637 ci, expired, key := c.get(dnsMsg)
638 require.NotNilf(t, ci, "no cache found for %s", host)
639
640 assert.False(t, expired)
641 assert.Equal(t, msgToKey(req), key)
642
643 requireEqualMsgs(t, ci.m, dnsMsg)
644 }
645
646 assert.Eventuallyf(t, func() bool {
647 ci, _, _ := c.get(req)
648
649 return ci == nil
650 }, cacheTimeout, cacheTick, "cache for %s should already be removed", host)
651}
652
653func TestCache_getWithSubnet(t *testing.T) {
654 const testFQDN = "example.com."

Callers 1

TestCache_concurrentFunction · 0.85

Calls 5

newRRFunction · 0.85
msgToKeyFunction · 0.85
requireEqualMsgsFunction · 0.85
setMethod · 0.80
getMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…