Skip to content

Commit

Permalink
upstream: imp tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizzick committed May 30, 2024
1 parent e1c031e commit d2db301
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 9 deletions.
4 changes: 4 additions & 0 deletions upstream/dnscrypt_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ func startTestDNSCryptServer(
// Tests

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

// AdGuard DNS (DNSCrypt)
address := "sdns://AQMAAAAAAAAAETk0LjE0MC4xNC4xNDo1NDQzINErR_JS3PLCu_iZEIbq95zkSV2LFsigxDIuUso_OQhzIjIuZG5zY3J5cHQuZGVmYXVsdC5uczEuYWRndWFyZC5jb20"
u, err := AddressToUpstream(address, &Options{Timeout: dialTimeout})
Expand Down Expand Up @@ -153,6 +155,8 @@ func TestDNSCrypt_Exchange_truncated(t *testing.T) {
}

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

// Prepare the test DNSCrypt server config
rc, err := dnscrypt.GenerateResolverConfig("example.org", nil)
require.NoError(t, err)
Expand Down
18 changes: 14 additions & 4 deletions upstream/doh_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
)

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

testCases := []struct {
name string
expectedProtocol HTTPVersion
Expand Down Expand Up @@ -60,6 +62,8 @@ func TestUpstreamDoH(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

srv := startDoHServer(t, testDoHServerOptions{
http3Enabled: tc.http3Enabled,
delayHandshakeH2: tc.delayHandshakeH2,
Expand Down Expand Up @@ -109,6 +113,8 @@ func TestUpstreamDoH(t *testing.T) {
}

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

testCases := []struct {
name string
expectedProtocol HTTPVersion
Expand Down Expand Up @@ -151,9 +157,7 @@ func TestUpstreamDoH_raceReconnect(t *testing.T) {
// important to test for race conditions.
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
if t.Name() == "TestUpstreamDoH_raceReconnect/http3" {
t.Skip("TODO(e.burkov): remove the skip when quic-go is fixed")
}
t.Parallel()

const timeout = time.Millisecond * 100
var requestsCount int32
Expand Down Expand Up @@ -193,6 +197,8 @@ func TestUpstreamDoH_raceReconnect(t *testing.T) {
}

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

testCases := []struct {
name string
httpVersions []HTTPVersion
Expand All @@ -206,6 +212,8 @@ func TestUpstreamDoH_serverRestart(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

var addr netip.AddrPort
var upsAddr string
var u Upstream
Expand All @@ -226,7 +234,7 @@ func TestUpstreamDoH_serverRestart(t *testing.T) {
u, err = AddressToUpstream(upsAddr, &Options{
InsecureSkipVerify: true,
HTTPVersions: tc.httpVersions,
Timeout: time.Second,
Timeout: 100 * time.Millisecond,
})
require.NoError(t, err)

Expand Down Expand Up @@ -261,6 +269,8 @@ func TestUpstreamDoH_serverRestart(t *testing.T) {
}

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

// Run the first server instance.
srv := startDoHServer(t, testDoHServerOptions{
http3Enabled: true,
Expand Down
7 changes: 6 additions & 1 deletion upstream/doq_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ func TestUpstream_Exchange_quicServerCloseConn(t *testing.T) {
}

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

// Use the same tlsConf for all servers to preserve the data necessary for
// 0-RTT connections.
tlsConf, rootCAs := createServerTLSConfig(t, "127.0.0.1")
Expand All @@ -144,7 +146,10 @@ func TestUpstreamDoQ_serverRestart(t *testing.T) {
}).String()

var err error
u, err = AddressToUpstream(upsStr, &Options{RootCAs: rootCAs})
u, err = AddressToUpstream(
upsStr,
&Options{RootCAs: rootCAs, Timeout: 100 * time.Millisecond},
)
require.NoError(t, err)

checkUpstream(t, u, upsStr)
Expand Down
2 changes: 1 addition & 1 deletion upstream/parallel_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

const (
timeout = 5 * time.Second
timeout = 2 * time.Second
)

// TestExchangeParallel launches several parallel exchanges
Expand Down
4 changes: 4 additions & 0 deletions upstream/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func TestNewUpstreamResolver(t *testing.T) {
}

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

withTimeoutOpt := &upstream.Options{Timeout: 3 * time.Second}

testCases := []struct {
Expand Down Expand Up @@ -93,6 +95,8 @@ func TestNewUpstreamResolver_validity(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

r, err := upstream.NewUpstreamResolver(tc.addr, withTimeoutOpt)
if tc.wantErrMsg != "" {
assert.Equal(t, tc.wantErrMsg, err.Error())
Expand Down
24 changes: 21 additions & 3 deletions upstream/upstream_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func TestMain(m *testing.M) {
}

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

const (
timeout = 100 * time.Millisecond
count = 10
Expand Down Expand Up @@ -99,12 +101,16 @@ func TestUpstream_bootstrapTimeout(t *testing.T) {
}

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

const upsTimeout = 500 * time.Second

googleRslv, err := NewUpstreamResolver("8.8.8.8:53", &Options{
Timeout: timeout,
Timeout: upsTimeout,
})
require.NoError(t, err)
cloudflareRslv, err := NewUpstreamResolver("1.0.0.1:53", &Options{
Timeout: timeout,
Timeout: upsTimeout,
})
require.NoError(t, err)

Expand Down Expand Up @@ -196,9 +202,11 @@ func TestUpstreams(t *testing.T) {

for _, test := range upstreams {
t.Run(test.address, func(t *testing.T) {
t.Parallel()

u, upsErr := AddressToUpstream(
test.address,
&Options{Bootstrap: test.bootstrap, Timeout: timeout},
&Options{Bootstrap: test.bootstrap, Timeout: upsTimeout},
)
require.NoErrorf(t, upsErr, "failed to generate upstream from address %s", test.address)
testutil.CleanupAndRequireSuccess(t, u.Close)
Expand Down Expand Up @@ -341,6 +349,8 @@ func TestAddressToUpstream_bads(t *testing.T) {
}

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

upstreams := []struct {
address string
bootstrap string
Expand Down Expand Up @@ -377,6 +387,8 @@ func TestUpstreamDoTBootstrap(t *testing.T) {

// Test for DoH and DoT upstreams with two bootstraps (only one is valid)
func TestUpstreamsInvalidBootstrap(t *testing.T) {
t.Parallel()

upstreams := []struct {
address string
bootstrap []string
Expand Down Expand Up @@ -404,6 +416,8 @@ func TestUpstreamsInvalidBootstrap(t *testing.T) {

for _, tc := range upstreams {
t.Run(tc.address, func(t *testing.T) {
t.Parallel()

var rslv ConsequentResolver
for _, b := range tc.bootstrap {
r, err := NewUpstreamResolver(b, &Options{
Expand Down Expand Up @@ -432,6 +446,8 @@ func TestUpstreamsInvalidBootstrap(t *testing.T) {
}

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

h := func(w dns.ResponseWriter, m *dns.Msg) {
require.NoError(testutil.PanicT{}, w.WriteMsg(respondToTestMessage(m)))
}
Expand Down Expand Up @@ -478,6 +494,8 @@ func TestAddressToUpstream_StaticResolver(t *testing.T) {

for _, tc := range upstreams {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

opts := &Options{
Bootstrap: tc.rslv,
Timeout: timeout,
Expand Down

0 comments on commit d2db301

Please sign in to comment.