Skip to content

Commit 1f267da

Browse files
vroldanbetclaude
andauthored
test: fix race condition in TestRecursiveCheckStrategies (#2893)
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 1ca0250 commit 1f267da

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pkg/query/recursive_strategies_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ func TestRecursiveCheckStrategies(t *testing.T) {
4141
ds, err := memdb.NewMemdbDatastore(0, 0, memdb.DisableGC)
4242
require.NoError(t, err)
4343

44-
queryCtx := NewLocalContext(context.Background(),
45-
WithReader(ds.SnapshotReader(datastore.NoRevision)))
46-
4744
// Test all three strategies
4845
strategies := []struct {
4946
name string
@@ -57,6 +54,13 @@ func TestRecursiveCheckStrategies(t *testing.T) {
5754
for _, tc := range strategies {
5855
t.Run(tc.name, func(t *testing.T) {
5956
t.Parallel()
57+
58+
// Create a separate Context for each parallel subtest to avoid races.
59+
// Contexts contain mutable state (e.g., recursiveFrontierCollectors)
60+
// that must not be shared across concurrent goroutines.
61+
queryCtx := NewLocalContext(context.Background(),
62+
WithReader(ds.SnapshotReader(datastore.NoRevision)))
63+
6064
// Create recursive iterator with the specific strategy
6165
recursive := NewRecursiveIterator(union, "folder", "view")
6266
recursive.checkStrategy = tc.strategy

0 commit comments

Comments
 (0)