Make race detector not fire on this simple test
Do the standard Lock()/modify/Unlock() dance.
This commit is contained in:
parent
45c5ad39c5
commit
6f477021c0
|
@ -8,6 +8,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -163,13 +164,22 @@ func TestRootServer(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var MAXREC = 0
|
type maxRec struct {
|
||||||
|
max int
|
||||||
|
sync.RWMutex
|
||||||
|
}
|
||||||
|
|
||||||
|
var M = new(maxRec)
|
||||||
|
|
||||||
func HelloServerLargeResponse(resp ResponseWriter, req *Msg) {
|
func HelloServerLargeResponse(resp ResponseWriter, req *Msg) {
|
||||||
m := new(Msg)
|
m := new(Msg)
|
||||||
m.SetReply(req)
|
m.SetReply(req)
|
||||||
m.Authoritative = true
|
m.Authoritative = true
|
||||||
for i := 0; i < MAXREC; i++ {
|
m1 := 0
|
||||||
|
M.RLock()
|
||||||
|
m1 = M.max
|
||||||
|
M.RUnlock()
|
||||||
|
for i := 0; i < m1; i++ {
|
||||||
aRec := &A{
|
aRec := &A{
|
||||||
Hdr: RR_Header{
|
Hdr: RR_Header{
|
||||||
Name: req.Question[0].Name,
|
Name: req.Question[0].Name,
|
||||||
|
@ -205,14 +215,18 @@ func TestServingLargeResponses(t *testing.T) {
|
||||||
|
|
||||||
c := new(Client)
|
c := new(Client)
|
||||||
c.Net = "udp"
|
c.Net = "udp"
|
||||||
MAXREC = 2
|
M.Lock()
|
||||||
|
M.max = 2
|
||||||
|
M.Unlock()
|
||||||
_, _, err := c.Exchange(m, "127.0.0.1:10000")
|
_, _, err := c.Exchange(m, "127.0.0.1:10000")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Logf("Failed to exchange: %s", err.Error())
|
t.Logf("Failed to exchange: %s", err.Error())
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
// This must fail
|
// This must fail
|
||||||
MAXREC = 20
|
M.Lock()
|
||||||
|
M.max = 20
|
||||||
|
M.Unlock()
|
||||||
_, _, err = c.Exchange(m, "127.0.0.1:10000")
|
_, _, err = c.Exchange(m, "127.0.0.1:10000")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Logf("Failed to fail exchange, this should generate packet error")
|
t.Logf("Failed to fail exchange, this should generate packet error")
|
||||||
|
|
Loading…
Reference in New Issue