Skip to content

Commit

Permalink
proxy: imp tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizzick committed May 30, 2024
1 parent 1ff1d6d commit e1c031e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 deletions.
2 changes: 1 addition & 1 deletion proxy/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestServeCached(t *testing.T) {

// Create a DNS-over-UDP client connection.
addr := dnsProxy.Addr(ProtoUDP)
client := &dns.Client{Net: "udp", Timeout: 500 * time.Millisecond}
client := &dns.Client{Net: "udp", Timeout: testTimeout}

// Create a DNS request.
request := (&dns.Msg{}).SetQuestion("google.com.", dns.TypeA)
Expand Down
3 changes: 1 addition & 2 deletions proxy/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"net"
"sync"
"testing"
"time"

"github.com/AdguardTeam/golibs/testutil"
"github.com/miekg/dns"
Expand Down Expand Up @@ -53,7 +52,7 @@ func TestFilteringHandler(t *testing.T) {

// Create a DNS-over-UDP client connection
addr := dnsProxy.Addr(ProtoUDP)
client := &dns.Client{Net: "udp", Timeout: 500 * time.Millisecond}
client := &dns.Client{Net: "udp", Timeout: testTimeout}

// Send the first message (not blocked)
req := newTestMessage()
Expand Down
22 changes: 11 additions & 11 deletions proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,18 +687,18 @@ func newLocalUpstreamListener(t *testing.T, port uint16, h dns.Handler) (real ne
}

func TestFallback(t *testing.T) {
t.Parallel()

responseCh := make(chan uint16)
failCh := make(chan uint16)

const timeout = 1 * time.Second

successHandler := dns.HandlerFunc(func(w dns.ResponseWriter, r *dns.Msg) {
testutil.RequireSend(testutil.PanicT{}, responseCh, r.Id, timeout)
testutil.RequireSend(testutil.PanicT{}, responseCh, r.Id, testTimeout)

require.NoError(testutil.PanicT{}, w.WriteMsg((&dns.Msg{}).SetReply(r)))
})
failHandler := dns.HandlerFunc(func(w dns.ResponseWriter, r *dns.Msg) {
testutil.RequireSend(testutil.PanicT{}, failCh, r.Id, timeout)
testutil.RequireSend(testutil.PanicT{}, failCh, r.Id, testTimeout)

require.NoError(testutil.PanicT{}, w.WriteMsg(&dns.Msg{}))
})
Expand All @@ -721,7 +721,7 @@ func TestFallback(t *testing.T) {
TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
UpstreamConfig: newTestUpstreamConfig(
t,
timeout,
testTimeout,
failAddr,
"[/specific.example/]"+alsoSuccessAddr,
// almost.failing.example will fall here first.
Expand All @@ -730,7 +730,7 @@ func TestFallback(t *testing.T) {
TrustedProxies: defaultTrustedProxies,
Fallbacks: newTestUpstreamConfig(
t,
timeout,
testTimeout,
failAddr,
successAddr,
"[/failing.example/]"+failAddr,
Expand Down Expand Up @@ -785,7 +785,7 @@ func TestFallback(t *testing.T) {
require.NoError(t, err)

for _, ch := range tc.wantSignals {
reqID, ok := testutil.RequireReceive(testutil.PanicT{}, ch, timeout)
reqID, ok := testutil.RequireReceive(testutil.PanicT{}, ch, testTimeout)
require.True(t, ok)

assert.Equal(t, req.Id, reqID)
Expand Down Expand Up @@ -871,7 +871,7 @@ func TestRefuseAny(t *testing.T) {

// Create a DNS-over-UDP client connection
addr := dnsProxy.Addr(ProtoUDP)
client := &dns.Client{Net: "udp", Timeout: 500 * time.Millisecond}
client := &dns.Client{Net: "udp", Timeout: testTimeout}

// Create a DNS request
request := (&dns.Msg{
Expand Down Expand Up @@ -905,7 +905,7 @@ func TestInvalidDNSRequest(t *testing.T) {
testutil.CleanupAndRequireSuccess(t, func() (err error) { return dnsProxy.Shutdown(ctx) })

// Create a DNS-over-UDP client connection
client := &dns.Client{Net: "udp", Timeout: 500 * time.Millisecond}
client := &dns.Client{Net: "udp", Timeout: testTimeout}

// Create a DNS request
request := &dns.Msg{
Expand All @@ -925,7 +925,7 @@ func TestResponseInRequest(t *testing.T) {
dnsProxy := mustStartDefaultProxy(t)

addr := dnsProxy.Addr(ProtoUDP)
client := &dns.Client{Net: "udp", Timeout: 500 * time.Millisecond}
client := &dns.Client{Net: "udp", Timeout: testTimeout}

req := newTestMessage()
req.Response = true
Expand All @@ -943,7 +943,7 @@ func TestNoQuestion(t *testing.T) {
dnsProxy := mustStartDefaultProxy(t)

addr := dnsProxy.Addr(ProtoUDP)
client := &dns.Client{Net: "udp", Timeout: 500 * time.Millisecond}
client := &dns.Client{Net: "udp", Timeout: testTimeout}

req := newTestMessage()
req.Question = nil
Expand Down
3 changes: 1 addition & 2 deletions proxy/ratelimit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"net"
"net/netip"
"testing"
"time"

"github.com/AdguardTeam/golibs/testutil"
"github.com/miekg/dns"
Expand All @@ -31,7 +30,7 @@ func TestRatelimitingProxy(t *testing.T) {

// Create a DNS-over-UDP client connection
addr := dnsProxy.Addr(ProtoUDP)
client := &dns.Client{Net: "udp", Timeout: 500 * time.Millisecond}
client := &dns.Client{Net: "udp", Timeout: testTimeout}

// Send the first message (not blocked)
req := newTestMessage()
Expand Down
5 changes: 2 additions & 3 deletions proxy/upstreams_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package proxy

import (
"testing"
"time"

"github.com/AdguardTeam/dnsproxy/upstream"
"github.com/AdguardTeam/golibs/errors"
Expand Down Expand Up @@ -278,7 +277,7 @@ func TestGetUpstreamsForDomainWithoutDuplicates(t *testing.T) {
&upstream.Options{
InsecureSkipVerify: false,
Bootstrap: nil,
Timeout: 1 * time.Second,
Timeout: testTimeout,
},
)
assert.NoError(t, err)
Expand Down Expand Up @@ -455,7 +454,7 @@ func BenchmarkGetUpstreamsForDomain(b *testing.B) {
&upstream.Options{
InsecureSkipVerify: false,
Bootstrap: nil,
Timeout: 1 * time.Second,
Timeout: testTimeout,
},
)

Expand Down

0 comments on commit e1c031e

Please sign in to comment.