mirror of
https://blitiri.com.ar/repos/chasquid
synced 2026-02-08 22:35:58 +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
|
wg sync.WaitGroup
|
||||||
requests []*deliverRequest
|
requests []*deliverRequest
|
||||||
reqFor map[string]*deliverRequest
|
reqFor map[string]*deliverRequest
|
||||||
|
sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tc *TestCourier) Deliver(from string, to string, data []byte) (error, bool) {
|
func (tc *TestCourier) Deliver(from string, to string, data []byte) (error, bool) {
|
||||||
defer tc.wg.Done()
|
defer tc.wg.Done()
|
||||||
dr := &deliverRequest{from, to, data}
|
dr := &deliverRequest{from, to, data}
|
||||||
|
tc.Lock()
|
||||||
tc.requests = append(tc.requests, dr)
|
tc.requests = append(tc.requests, dr)
|
||||||
tc.reqFor[to] = dr
|
tc.reqFor[to] = dr
|
||||||
|
tc.Unlock()
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user