mirror of
https://github.com/kemko/nomad.git
synced 2026-01-07 19:05:42 +03:00
test: fix concurrent map access in TestStatsFetcher (#14496)
The map of in-flight RPCs gets cleared by a goroutine in the test without first locking it to make sure that it's not being accessed concurrently by the stats fetcher itself. This can cause a panic in tests.
This commit is contained in:
@@ -71,7 +71,11 @@ func TestStatsFetcher(t *testing.T) {
|
||||
// from it.
|
||||
func() {
|
||||
s1.statsFetcher.inflight[raft.ServerID(s3.config.NodeID)] = struct{}{}
|
||||
defer delete(s1.statsFetcher.inflight, raft.ServerID(s3.config.NodeID))
|
||||
defer func() {
|
||||
s1.statsFetcher.inflightLock.Lock()
|
||||
delete(s1.statsFetcher.inflight, raft.ServerID(s3.config.NodeID))
|
||||
s1.statsFetcher.inflightLock.Unlock()
|
||||
}()
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
|
||||
Reference in New Issue
Block a user