mirror of https://github.com/0xERR0R/blocky.git
refactor(tests): use a `const timeout` to simplify race avoidance
This commit is contained in:
parent
8c7b89cbb3
commit
8ad83d0568
|
@ -3,7 +3,6 @@ package resolver
|
|||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/0xERR0R/blocky/config"
|
||||
. "github.com/0xERR0R/blocky/helpertest"
|
||||
|
@ -16,8 +15,6 @@ import (
|
|||
|
||||
var _ = Describe("ParallelBestResolver", Label("parallelBestResolver"), func() {
|
||||
const (
|
||||
timeout = 50 * time.Millisecond
|
||||
|
||||
verifyUpstreams = true
|
||||
noVerifyUpstreams = false
|
||||
)
|
||||
|
|
|
@ -13,6 +13,10 @@ import (
|
|||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
const (
|
||||
timeout = 50 * time.Millisecond
|
||||
)
|
||||
|
||||
var defaultUpstreamsConfig config.Upstreams
|
||||
|
||||
func init() {
|
||||
|
@ -27,7 +31,7 @@ func init() {
|
|||
}
|
||||
|
||||
// Shorter timeout for tests
|
||||
defaultUpstreamsConfig.Timeout = config.Duration(50 * time.Millisecond)
|
||||
defaultUpstreamsConfig.Timeout = config.Duration(timeout)
|
||||
}
|
||||
|
||||
func TestResolver(t *testing.T) {
|
||||
|
|
|
@ -164,7 +164,7 @@ var _ = Describe("StrictResolver", Label("strictResolver"), func() {
|
|||
))
|
||||
})
|
||||
})
|
||||
When("first upstream exceeds upstreamTimeout", func() {
|
||||
When("first upstream times-out", func() {
|
||||
BeforeEach(func() {
|
||||
testUpstream1 = NewMockUDPUpstreamServer().WithAnswerFn(func(request *dns.Msg) (response *dns.Msg) {
|
||||
response, err := util.NewMsgWithAnswer("example.com", 123, A, "123.124.122.1")
|
||||
|
@ -190,7 +190,7 @@ var _ = Describe("StrictResolver", Label("strictResolver"), func() {
|
|||
))
|
||||
})
|
||||
})
|
||||
When("all upstreams exceed upsteamTimeout", func() {
|
||||
When("all upstreams timeout", func() {
|
||||
JustBeforeEach(func() {
|
||||
testUpstream1 = NewMockUDPUpstreamServer().WithAnswerFn(func(request *dns.Msg) (response *dns.Msg) {
|
||||
response, err := util.NewMsgWithAnswer("example.com", 123, A, "123.124.122.1")
|
||||
|
|
|
@ -113,8 +113,6 @@ var _ = Describe("UpstreamResolver", Label("upstreamResolver"), func() {
|
|||
var counter int32
|
||||
var attemptsWithTimeout int32
|
||||
BeforeEach(func() {
|
||||
timeout := sutConfig.Timeout.ToDuration() // avoid data race
|
||||
|
||||
resolveFn := func(request *dns.Msg) *dns.Msg {
|
||||
// timeout on first x attempts
|
||||
if atomic.AddInt32(&counter, 1) <= atomic.LoadInt32(&attemptsWithTimeout) {
|
||||
|
|
Loading…
Reference in New Issue