Skip to content

Commit

Permalink
fix(tests): don't make following requests wait on the first
Browse files Browse the repository at this point in the history
This could cause tests with delays much longer than the timeout to
timeout multiple times in a row just because the first `answerFn` call
was stalled.
  • Loading branch information
ThinkChaos committed Nov 23, 2023
1 parent 7feaba4 commit 08a3df6
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions resolver/mock_udp_upstream_server.go
Expand Up @@ -122,36 +122,34 @@ func (t *MockUDPUpstreamServer) Start() config.Upstream {
break
}

msg := new(dns.Msg)
err = msg.Unpack(buffer[0 : n-1])
go func() {
msg := new(dns.Msg)
err = msg.Unpack(buffer[0 : n-1])

util.FatalOnError("can't deserialize message: ", err)
util.FatalOnError("can't deserialize message: ", err)

response := t.answerFn(msg)
response := t.answerFn(msg)

atomic.AddInt32(&t.callCount, 1)
// nil should indicate an error
if response == nil {
_, _ = ln.WriteToUDP([]byte("dummy"), addr)
atomic.AddInt32(&t.callCount, 1)
// nil should indicate an error
if response == nil {
_, _ = ln.WriteToUDP([]byte("dummy"), addr)

continue
}
return
}

rCode := response.Rcode
response.SetReply(msg)
rCode := response.Rcode
response.SetReply(msg)

if rCode != 0 {
response.Rcode = rCode
}
if rCode != 0 {
response.Rcode = rCode
}

b, err := response.Pack()
util.FatalOnError("can't serialize message: ", err)
b, err := response.Pack()
util.FatalOnError("can't serialize message: ", err)

_, err = ln.WriteToUDP(b, addr)
if err != nil {
// closed
break
}
_, _ = ln.WriteToUDP(b, addr)
}()
}
}()

Expand Down

0 comments on commit 08a3df6

Please sign in to comment.