Skip to content

Commit 398513d

Browse files
authored
Join scanner goroutines in TestScanRightDeleteRandom (#4354)
TestScanRightDeleteRandom panics with "Fail in goroutine after TestScanRightDeleteRandom has completed". Its scanner goroutines are never joined. After `close(stop)` the test clears the list and returns, while scanners can still be blocked in `WaitFront(t.Context())`. When the test context is cancelled, `WaitFront` returns an error and the scanner calls `require.NoError` on a finished test. The scanners now run in an errgroup and return `WaitFront` errors instead of calling `require` off the test goroutine. After `close(stop)` the test waits on the group before clearing the list, then asserts its error on the test goroutine. Flaked in: https://github.com/sei-protocol/sei-chain/actions/runs/34233688470/job/102085875556
1 parent b7ab9ac commit 398513d

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

‎sei-tendermint/internal/libs/clist/clist_test.go‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
"github.com/stretchr/testify/require"
12+
"golang.org/x/sync/errgroup"
1213
)
1314

1415
func TestSmall(t *testing.T) {
@@ -192,8 +193,10 @@ func TestScanRightDeleteRandom(t *testing.T) {
192193
}
193194

194195
// Launch scanner routines that will rapidly iterate over elements.
196+
g, ctx := errgroup.WithContext(t.Context())
195197
for i := 0; i < numScanners; i++ {
196-
go func(scannerID int) {
198+
scannerID := i
199+
g.Go(func() error {
197200
var el *CElement[int]
198201
restartCounter := 0
199202
counter := 0
@@ -207,15 +210,18 @@ func TestScanRightDeleteRandom(t *testing.T) {
207210
}
208211
if el == nil {
209212
var err error
210-
el, err = l.WaitFront(t.Context())
211-
require.NoError(t, err)
213+
el, err = l.WaitFront(ctx)
214+
if err != nil {
215+
return err
216+
}
212217
restartCounter++
213218
}
214219
el = el.Next()
215220
counter++
216221
}
217222
fmt.Printf("Scanner %v restartCounter: %v counter: %v\n", scannerID, restartCounter, counter)
218-
}(i)
223+
return nil
224+
})
219225
}
220226

221227
// Remove an element, push back an element.
@@ -238,8 +244,9 @@ func TestScanRightDeleteRandom(t *testing.T) {
238244

239245
}
240246

241-
// Stop scanners
247+
// Stop scanners and wait for them before the list is emptied.
242248
close(stop)
249+
require.NoError(t, g.Wait())
243250

244251
// And remove all the elements.
245252
l.Clear()

0 commit comments

Comments
 (0)