mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-17 14:37:02 +00:00
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.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user