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

Function TestFallback

proxy/proxy_internal_test.go:717–822  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

715}
716
717func TestFallback(t *testing.T) {
718 t.Parallel()
719
720 responseCh := make(chan uint16)
721 failCh := make(chan uint16)
722
723 successHandler := dns.HandlerFunc(func(w dns.ResponseWriter, r *dns.Msg) {
724 testutil.RequireSend(testutil.PanicT{}, responseCh, r.Id, testTimeout)
725
726 require.NoError(testutil.PanicT{}, w.WriteMsg((&dns.Msg{}).SetReply(r)))
727 })
728 failHandler := dns.HandlerFunc(func(w dns.ResponseWriter, r *dns.Msg) {
729 testutil.RequireSend(testutil.PanicT{}, failCh, r.Id, testTimeout)
730
731 require.NoError(testutil.PanicT{}, w.WriteMsg(&dns.Msg{}))
732 })
733
734 successAddr := (&url.URL{
735 Scheme: string(ProtoTCP),
736 Host: newLocalUpstreamListener(t, 0, successHandler).String(),
737 }).String()
738 alsoSuccessAddr := (&url.URL{
739 Scheme: string(ProtoTCP),
740 Host: newLocalUpstreamListener(t, 0, successHandler).String(),
741 }).String()
742 failAddr := (&url.URL{
743 Scheme: string(ProtoTCP),
744 Host: newLocalUpstreamListener(t, 0, failHandler).String(),
745 }).String()
746
747 dnsProxy := mustNew(t, &Config{
748 Logger: testLogger,
749 UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
750 TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
751 UpstreamConfig: newTestUpstreamConfig(
752 t,
753 testTimeout,
754 failAddr,
755 "[/specific.example/]"+alsoSuccessAddr,
756 // almost.failing.example will fall here first.
757 "[/failing.example/]"+failAddr,
758 ),
759 TrustedProxies: defaultTrustedProxies,
760 Fallbacks: newTestUpstreamConfig(
761 t,
762 testTimeout,
763 failAddr,
764 successAddr,
765 "[/failing.example/]"+failAddr,
766 "[/almost.failing.example/]"+alsoSuccessAddr,
767 ),
768 })
769
770 servicetest.RequireRun(t, dnsProxy, testTimeout)
771
772 conn, err := dns.Dial("tcp", dnsProxy.Addr(ProtoTCP).String())
773 require.NoError(t, err)
774

Callers

nothing calls this directly

Calls 6

newLocalUpstreamListenerFunction · 0.85
mustNewFunction · 0.85
newTestUpstreamConfigFunction · 0.85
newHostTestMessageFunction · 0.85
AddrMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…