git » chasquid » commit 641406c

queue: Fix race in tests

author Alberto Bertogli
2016-10-08 11:17:16 UTC
committer Alberto Bertogli
2016-10-09 23:51:05 UTC
parent 08a5d19941f0329d02b1a350cd3652ed3ddd6c30

queue: Fix race in tests

The test courier has a racy map access, and this started to manifest
after some recent changes. This patch fixes the race by implementing the
corresponding locks.

internal/queue/queue_test.go +3 -0

diff --git a/internal/queue/queue_test.go b/internal/queue/queue_test.go
index 11d6ed5..b77ebe1 100644
--- a/internal/queue/queue_test.go
+++ b/internal/queue/queue_test.go
@@ -41,13 +41,16 @@ type TestCourier struct {
 	wg       sync.WaitGroup
 	requests []*deliverRequest
 	reqFor   map[string]*deliverRequest
+	sync.Mutex
 }
 
 func (tc *TestCourier) Deliver(from string, to string, data []byte) (error, bool) {
 	defer tc.wg.Done()
 	dr := &deliverRequest{from, to, data}
+	tc.Lock()
 	tc.requests = append(tc.requests, dr)
 	tc.reqFor[to] = dr
+	tc.Unlock()
 	return nil, false
 }