Address review: use slices.Clone, simplify concurrent test

- Replace manual make+copy with slices.Clone in Snapshot()
- Remove redundant _ = len(data); Snapshot() call alone is
  sufficient to exercise the lock under -race
This commit is contained in:
dolonet
2026-03-30 16:17:51 +00:00
parent 73c6a3aa37
commit eedee63143
2 changed files with 4 additions and 4 deletions
@@ -1,6 +1,7 @@
package doppel
import (
"slices"
"sync"
"time"
)
@@ -43,8 +44,7 @@ func (s *ScoutConnCollected) MarkWrite() {
// Snapshot returns a copy of the collected data and the write index.
func (s *ScoutConnCollected) Snapshot() ([]ScoutConnResult, int) {
s.mu.Lock()
snapshot := make([]ScoutConnResult, len(s.data))
copy(snapshot, s.data)
snapshot := slices.Clone(s.data)
writeIndex := s.writeIndex
s.mu.Unlock()
@@ -68,8 +68,8 @@ func (suite *ScoutConnCollectedTestSuite) TestConcurrentAddSnapshot() {
defer wg.Done()
for i := 0; i < 1000; i++ {
data, _ := collected.Snapshot()
_ = len(data)
// call Snapshot concurrently to exercise the lock under -race
collected.Snapshot() //nolint:errcheck
}
}()