Guard request counter in ipfs mock with mutex
Fixes several data races across multiple tests.
This commit is contained in:
parent
cb4023855c
commit
cda59b656e
|
@ -40,9 +40,11 @@ type IpfsMock struct {
|
|||
Port int
|
||||
pinMap state.State
|
||||
BlockStore map[string][]byte
|
||||
reqCounts map[string]int
|
||||
reqCounter chan string
|
||||
|
||||
reqCountsMux sync.Mutex // guards access to reqCounts
|
||||
reqCounts map[string]int
|
||||
|
||||
closeMux sync.Mutex
|
||||
closed bool
|
||||
}
|
||||
|
@ -142,18 +144,20 @@ func NewIpfsMock(t *testing.T) *IpfsMock {
|
|||
m.Port = i
|
||||
m.Addr = h[0]
|
||||
return m
|
||||
|
||||
}
|
||||
|
||||
func (m *IpfsMock) countRequests() {
|
||||
for str := range m.reqCounter {
|
||||
m.reqCountsMux.Lock()
|
||||
m.reqCounts[str]++
|
||||
m.reqCountsMux.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
// GetCount allows to get the number of times and endpoint was called.
|
||||
// Do not use concurrently to requests happening.
|
||||
func (m *IpfsMock) GetCount(path string) int {
|
||||
m.reqCountsMux.Lock()
|
||||
defer m.reqCountsMux.Unlock()
|
||||
return m.reqCounts[path]
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user