Skip to content

Commit

Permalink
all: imp code
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizzick committed May 31, 2024
1 parent 9d11c99 commit 9a452ed
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
17 changes: 14 additions & 3 deletions proxy/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ func TestServeCached(t *testing.T) {

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

// Create a DNS request.
request := (&dns.Msg{}).SetQuestion("google.com.", dns.TypeA)
Expand Down Expand Up @@ -270,6 +273,14 @@ func TestCache_concurrent(t *testing.T) {
g.Wait()
}

const (
// cacheTick is a cache check period.
cacheTick = 50 * time.Millisecond

// cacheTimeout is the timeout of cache check.
cacheTimeout = 20 * cacheTick
)

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

Expand Down Expand Up @@ -324,7 +335,7 @@ func TestCacheExpiration(t *testing.T) {
}

return true
}, 1100*time.Millisecond, 50*time.Millisecond)
}, cacheTimeout, cacheTick)
}

func TestCacheExpirationWithTTLOverride(t *testing.T) {
Expand Down Expand Up @@ -609,7 +620,7 @@ func setAndGetCache(t *testing.T, c *cache, g *sync.WaitGroup, host, ip string)
ci, _, _ := c.get(dnsMsg)

return ci == nil
}, 1100*time.Millisecond, 100*time.Millisecond, "cache for %s should already be removed", host)
}, cacheTimeout, cacheTick, "cache for %s should already be removed", host)
}

func TestCache_getWithSubnet(t *testing.T) {
Expand Down
5 changes: 4 additions & 1 deletion proxy/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ func TestFilteringHandler(t *testing.T) {

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

// Send the first message (not blocked)
req := newTestMessage()
Expand Down
20 changes: 16 additions & 4 deletions proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,10 @@ func TestRefuseAny(t *testing.T) {

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

// Create a DNS request
request := (&dns.Msg{
Expand Down Expand Up @@ -935,7 +938,10 @@ 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: testTimeout}
client := &dns.Client{
Net: string(ProtoUDP),
Timeout: testTimeout,
}

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

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

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

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

req := newTestMessage()
req.Question = nil
Expand Down
5 changes: 4 additions & 1 deletion proxy/ratelimit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ func TestRatelimitingProxy(t *testing.T) {

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

// Send the first message (not blocked)
req := newTestMessage()
Expand Down
4 changes: 0 additions & 4 deletions upstream/dnscrypt_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
"github.com/stretchr/testify/require"
)

// Helpers

// dnsCryptHandlerFunc is a function-based implementation of the
// [dnscrypt.Handler] interface.
type dnsCryptHandlerFunc func(w dnscrypt.ResponseWriter, r *dns.Msg) (err error)
Expand Down Expand Up @@ -89,8 +87,6 @@ func startTestDNSCryptServer(
return stamp
}

// Tests

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

Expand Down

0 comments on commit 9a452ed

Please sign in to comment.