From 18ae818100950d8d677e9c67a5b868229ae14aa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20L=C3=B3pez?= <1953782+julio-lopez@users.noreply.github.com> Date: Tue, 16 Jun 2026 22:00:42 -0700 Subject: [PATCH] refactor(testing): wait for background work in test (#5430) Wait for background work to complete at the end of the test to avoid spurious failures due to context cancelation. Authored-by: @ashmrtn --- repo/content/content_manager_test.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/repo/content/content_manager_test.go b/repo/content/content_manager_test.go index f992ea5d8..f6e4e5b4d 100644 --- a/repo/content/content_manager_test.go +++ b/repo/content/content_manager_test.go @@ -1174,7 +1174,16 @@ func (s *contentManagerSuite) TestFlushWaitsForAllPendingWriters(t *testing.T) { // write one content in another goroutine // 'fs' is configured so that blob write takes several seconds to complete. - go writeContentAndVerify(ctx, t, bm, seededRandomData(1, maxPackSize)) + // Use a WaitGroup so the test doesn't end early and cause failures when the + // context gets canceled. Waiting should not invalidate other parts of the + // test because the initial blob count verification checks for multiple data + // blobs and the input data is sized such that multiple data blobs should be + // created. + var wg sync.WaitGroup + + wg.Go(func() { + writeContentAndVerify(ctx, t, bm, seededRandomData(1, maxPackSize)) + }) // wait enough time for the goroutine to start writing. time.Sleep(100 * time.Millisecond) @@ -1203,6 +1212,8 @@ func (s *contentManagerSuite) TestFlushWaitsForAllPendingWriters(t *testing.T) { PackBlobIDPrefixRegular: 2, indexBlobPrefix: 1, }) + + wg.Wait() } func (s *contentManagerSuite) verifyAllDataPresent(ctx context.Context, t *testing.T, st blob.Storage, contentIDs map[ID]bool) {