Skip to content

Commit a05c2c4

Browse files
jensneuseclaude
andcommitted
test: avoid pool pollution in TestSnapshotSlicesAreIndependent
Acquire + Release with RecordMutationEvent / RecordCacheOperationError leaves the pool holding a collector whose mutationEvents and cacheOpErrors slices are non-nil empty (NewCacheAnalyticsCollector leaves them nil; only ResetForReuse'd writes make them non-nil). Downstream tests that assert.Equal a full CacheAnalyticsSnapshot with those fields set to nil then pick up the polluted collector and fail. Use NewCacheAnalyticsCollector directly — the test's purpose is to prove Snapshot's slice independence, which does not require exercising the sync.Pool path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 5596ef0 commit a05c2c4

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

v2/pkg/engine/resolve/cache_analytics_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,8 +2045,12 @@ func TestSnapshotIndependentOfPooledCollector(t *testing.T) {
20452045
// the snapshot aliases the collector's backing arrays and the next request
20462046
// overwrites positions the caller is still reading.
20472047
func TestSnapshotSlicesAreIndependent(t *testing.T) {
2048-
c := AcquireCacheAnalyticsCollector()
2049-
t.Cleanup(func() { ReleaseCacheAnalyticsCollector(c) })
2048+
// Use a fresh collector instead of Acquire: RecordMutationEvent and
2049+
// RecordCacheOperationError initialize slices that NewCacheAnalyticsCollector
2050+
// leaves nil; Releasing the collector would leave the pool with a non-nil
2051+
// empty slice and break downstream tests that assert.Equal a snapshot with
2052+
// MutationEvents/CacheOpErrors set to nil.
2053+
c := NewCacheAnalyticsCollector()
20502054

20512055
c.RecordFetchTiming(FetchTimingEvent{DataSource: "ds-orig", DurationMs: 111})
20522056
c.RecordError(SubgraphErrorEvent{DataSource: "ds-orig"})

0 commit comments

Comments
 (0)