From 6f477021c03172463964cb51c6ede32feb56b1d2 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Fri, 28 Feb 2014 15:57:10 +0000 Subject: [PATCH] Make race detector not fire on this simple test Do the standard Lock()/modify/Unlock() dance. --- server_test.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/server_test.go b/server_test.go index 00d19ba3..ae549945 100644 --- a/server_test.go +++ b/server_test.go @@ -8,6 +8,7 @@ import ( "fmt" "net" "runtime" + "sync" "testing" "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) { m := new(Msg) m.SetReply(req) 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{ Hdr: RR_Header{ Name: req.Question[0].Name, @@ -205,14 +215,18 @@ func TestServingLargeResponses(t *testing.T) { c := new(Client) c.Net = "udp" - MAXREC = 2 + M.Lock() + M.max = 2 + M.Unlock() _, _, err := c.Exchange(m, "127.0.0.1:10000") if err != nil { t.Logf("Failed to exchange: %s", err.Error()) t.Fail() } // This must fail - MAXREC = 20 + M.Lock() + M.max = 20 + M.Unlock() _, _, err = c.Exchange(m, "127.0.0.1:10000") if err == nil { t.Logf("Failed to fail exchange, this should generate packet error")