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:
Tim Gross
2022-09-08 10:41:15 -04:00
committed by GitHub
parent 22403d357c
commit 3dab0249b4

View File

@@ -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()