From 641406cede9a4e9fb967c08650610a65f28a69b3 Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Sat, 8 Oct 2016 12:17:16 +0100 Subject: [PATCH] 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 +++ 1 file changed, 3 insertions(+) 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 }