Skip to content

Commit

Permalink
test: Fix flaky receive/multitsdb test (thanos-io#7694)
Browse files Browse the repository at this point in the history
There is race condition in `TestMultiTSDBPrune` due to a dangling goroutine
which can fail outside of the test function's lifetime if the database object
is closed before `Sync()` is finished.

Signed-off-by: Mikhail Nozdrachev <mikhail.nozdrachev@aiven.io>
  • Loading branch information
cincinnat authored and jnyi committed Oct 16, 2024
1 parent bda7585 commit 51c3df7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/receive/multitsdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,14 @@ func TestMultiTSDBPrune(t *testing.T) {
testutil.Equals(t, 3, len(m.TSDBLocalClients()))

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

g := sync.WaitGroup{}
defer func() { cancel(); g.Wait() }()

if test.bucket != nil {
g.Add(1)
go func() {
defer g.Done()
testutil.Ok(t, syncTSDBs(ctx, m, 10*time.Millisecond))
}()
}
Expand Down

0 comments on commit 51c3df7

Please sign in to comment.