test: Add retries to all tests
Add the retry loop from main in the event of lone failures. Hopefully this fixes test flakiness at the cost of taking longer
This commit is contained in:
parent
f2218481ee
commit
6e39d1e5f4
5 changed files with 62 additions and 20 deletions
|
@ -187,16 +187,26 @@ func TestRealPrint(t *testing.T) {
|
|||
|
||||
t.Run("", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
resp, err := query.CreateQuery(test)
|
||||
|
||||
var (
|
||||
res util.Response
|
||||
err error
|
||||
)
|
||||
for i := 0; i <= test.Request.Retries; i++ {
|
||||
res, err = query.CreateQuery(test)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
assert.NilError(t, err)
|
||||
|
||||
if test.JSON || test.XML || test.YAML {
|
||||
str := ""
|
||||
str, err = query.PrintSpecial(resp, test)
|
||||
str, err = query.PrintSpecial(res, test)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, str != "")
|
||||
}
|
||||
str, err := query.ToString(resp, test)
|
||||
str, err := query.ToString(res, test)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, str != "")
|
||||
})
|
||||
|
|
|
@ -3,10 +3,12 @@
|
|||
package resolvers_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"git.froth.zone/sam/awl/pkg/query"
|
||||
"git.froth.zone/sam/awl/pkg/util"
|
||||
"github.com/ameshkov/dnscrypt/v2"
|
||||
"github.com/miekg/dns"
|
||||
"gotest.tools/v3/assert"
|
||||
)
|
||||
|
@ -69,7 +71,17 @@ func TestDNSCrypt(t *testing.T) {
|
|||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
res, err := query.CreateQuery(test.opts)
|
||||
var (
|
||||
res util.Response
|
||||
err error
|
||||
)
|
||||
for i := 0; i <= test.opts.Request.Retries; i++ {
|
||||
res, err = query.CreateQuery(test.opts)
|
||||
if err == nil || errors.Is(err, dnscrypt.ErrInvalidDNSStamp) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
assert.Assert(t, res != util.Response{})
|
||||
} else {
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"errors"
|
||||
"testing"
|
||||
|
||||
"git.froth.zone/sam/awl/pkg/query"
|
||||
"git.froth.zone/sam/awl/pkg/resolvers"
|
||||
"git.froth.zone/sam/awl/pkg/util"
|
||||
"github.com/miekg/dns"
|
||||
|
@ -76,13 +77,16 @@ func TestHTTPS(t *testing.T) {
|
|||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
resolver, err := resolvers.LoadResolver(test.opts)
|
||||
assert.NilError(t, err)
|
||||
|
||||
msg := new(dns.Msg)
|
||||
msg.SetQuestion(test.opts.Request.Name, test.opts.Request.Type)
|
||||
// msg = msg.SetQuestion(testCase.Name, testCase.Type)
|
||||
res, err := resolver.LookUp(msg)
|
||||
var (
|
||||
res util.Response
|
||||
err error
|
||||
)
|
||||
for i := 0; i <= test.opts.Request.Retries; i++ {
|
||||
res, err = query.CreateQuery(test.opts)
|
||||
if err == nil || errors.Is(err, &resolvers.ErrHTTPStatus{}) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
assert.NilError(t, err)
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"git.froth.zone/sam/awl/pkg/resolvers"
|
||||
"git.froth.zone/sam/awl/pkg/query"
|
||||
"git.froth.zone/sam/awl/pkg/util"
|
||||
"github.com/miekg/dns"
|
||||
"gotest.tools/v3/assert"
|
||||
|
@ -74,6 +74,7 @@ func TestQuic(t *testing.T) {
|
|||
Type: dns.TypeA,
|
||||
Name: "git.froth.zone",
|
||||
Timeout: 10 * time.Millisecond,
|
||||
Retries: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -85,13 +86,16 @@ func TestQuic(t *testing.T) {
|
|||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
resolver, err := resolvers.LoadResolver(test.opts)
|
||||
assert.NilError(t, err)
|
||||
|
||||
msg := new(dns.Msg)
|
||||
msg.SetQuestion(test.opts.Request.Name, test.opts.Request.Type)
|
||||
|
||||
res, err := resolver.LookUp(msg)
|
||||
var (
|
||||
res util.Response
|
||||
err error
|
||||
)
|
||||
for i := 0; i <= test.opts.Request.Retries; i++ {
|
||||
res, err = query.CreateQuery(test.opts)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
assert.NilError(t, err)
|
||||
|
|
|
@ -3,12 +3,14 @@
|
|||
package resolvers_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.froth.zone/sam/awl/pkg/query"
|
||||
"git.froth.zone/sam/awl/pkg/util"
|
||||
"github.com/ameshkov/dnscrypt/v2"
|
||||
"github.com/miekg/dns"
|
||||
"gotest.tools/v3/assert"
|
||||
)
|
||||
|
@ -116,7 +118,17 @@ func TestResolve(t *testing.T) {
|
|||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
res, err := query.CreateQuery(test.opts)
|
||||
var (
|
||||
res util.Response
|
||||
err error
|
||||
)
|
||||
for i := 0; i <= test.opts.Request.Retries; i++ {
|
||||
res, err = query.CreateQuery(test.opts)
|
||||
if err == nil || errors.Is(err, dnscrypt.ErrInvalidDNSStamp) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, res != util.Response{})
|
||||
|
|
Loading…
Reference in a new issue