fix: resolve TestAddMultipleGCLive race condition (#10916)
test was expecting immediate GC lock acquisition after pipe close, but timing wasn't guaranteed. replaced blocking wait with 5-second timeout to handle timing variations while still detecting deadlocks.
Marcin Rataj committed
Aug 18, 2025 at 20:49 UTC
a81cc2928247829e12c2a76d8b7041232a9fe29c
1 file changed
+18
-3
core/coreunix/add_test.go
+18
-3
@@ -93,8 +93,15 @@ func TestAddMultipleGCLive(t *testing.T) {
93
// finish write and unblock gc
94
pipew1.Close()
95
96
- // Should have gotten the lock at this point
97
- <-gc1started
96
+ // Wait for GC to acquire the lock
97
+ // The adder needs to finish processing file 'a' and call maybePauseForGC
98
+ // when starting file 'b' before GC can proceed
99
+ select {
100
+ case <-gc1started:
101
+ // GC got the lock as expected
102
+ case <-time.After(5 * time.Second):
103
+ t.Fatal("timeout waiting for GC to start - possible deadlock")
104
+ }
105
106
removedHashes := make(map[string]struct{})
107
for r := range gc1out {
@@ -123,7 +130,15 @@ func TestAddMultipleGCLive(t *testing.T) {
130
131
pipew2.Close()
132
126
- <-gc2started
133
+ // Wait for second GC to acquire the lock
134
+ // The adder needs to finish processing file 'b' and call maybePauseForGC
135
+ // when starting file 'c' before GC can proceed
136
+ select {
137
+ case <-gc2started:
138
+ // GC got the lock as expected
139
+ case <-time.After(5 * time.Second):
140
+ t.Fatal("timeout waiting for second GC to start - possible deadlock")
141
+ }
142
143
for r := range gc2out {
144
if r.Error != nil {