fix: tighten ScoutConnCollected encapsulation and add concurrency test

- Move error check before Snapshot() to avoid unnecessary allocation
- Update existing tests to use Snapshot() instead of direct field access
- Add TestConcurrentAddSnapshot to explicitly exercise the mutex
This commit is contained in:
Alexey Dolotov
2026-03-30 15:05:50 +03:00
parent e54d9d60d3
commit 73c6a3aa37
2 changed files with 54 additions and 6 deletions
+6 -2
View File
@@ -61,10 +61,14 @@ func (s Scout) learn(ctx context.Context, url string) (ScoutResult, error) {
client.CloseIdleConnections()
}
if err != nil {
return ScoutResult{}, err
}
data, writeIndex := results.Snapshot()
if err != nil || len(data) == 0 {
return ScoutResult{}, err
if len(data) == 0 {
return ScoutResult{}, nil
}
var result ScoutResult