From 1e55e2d3aafc43dd7e59ea12f47ea555fa075b3e 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 23:13:24 -0700 Subject: [PATCH] refactor(testing): wait for routine to exit before test cleanup (#5432) Ensure background routine exits before cleaning up test environment --- repo/content/content_manager_test.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/repo/content/content_manager_test.go b/repo/content/content_manager_test.go index f6e4e5b4d..23b459577 100644 --- a/repo/content/content_manager_test.go +++ b/repo/content/content_manager_test.go @@ -1170,7 +1170,7 @@ func (s *contentManagerSuite) TestFlushWaitsForAllPendingWriters(t *testing.T) { fs.AddFault(blobtesting.MethodPutBlob).SleepFor(2 * time.Second) bm := s.newTestContentManagerWithTweaks(t, fs, nil) - defer bm.CloseShared(ctx) + t.Cleanup(func() { bm.CloseShared(testlogging.ContextForCleanup(t)) }) // write one content in another goroutine // 'fs' is configured so that blob write takes several seconds to complete. @@ -1185,6 +1185,10 @@ func (s *contentManagerSuite) TestFlushWaitsForAllPendingWriters(t *testing.T) { writeContentAndVerify(ctx, t, bm, seededRandomData(1, maxPackSize)) }) + // wait for background writeContentAndVerify routine to finish before + // performing the rest of the test cleanup, such as tearing down 'bm' + t.Cleanup(wg.Wait) + // wait enough time for the goroutine to start writing. time.Sleep(100 * time.Millisecond) @@ -1212,8 +1216,6 @@ 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) {