From 241c802981b71c36c0be1d069b087477424f4338 Mon Sep 17 00:00:00 2001 From: tamirms Date: Tue, 7 May 2024 11:31:02 +0100 Subject: [PATCH] fix data race in TestLedgerBufferClose --- ingest/ledgerbackend/buffered_storage_backend_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ingest/ledgerbackend/buffered_storage_backend_test.go b/ingest/ledgerbackend/buffered_storage_backend_test.go index af17bcfdff..f132bc9419 100644 --- a/ingest/ledgerbackend/buffered_storage_backend_test.go +++ b/ingest/ledgerbackend/buffered_storage_backend_test.go @@ -441,9 +441,12 @@ func TestLedgerBufferClose(t *testing.T) { partition := ledgerPerFileCount*partitionSize - 1 objectName := fmt.Sprintf("0-%d/%d.xdr.gz", partition, 3) + afterPrepareRange := make(chan struct{}) mockDataStore.On("GetFile", mock.Anything, objectName).Return(io.NopCloser(&bytes.Buffer{}), context.Canceled).Run(func(args mock.Arguments) { + <-afterPrepareRange go bsb.ledgerBuffer.close() }).Once() + t.Cleanup(func() { mockDataStore.AssertExpectations(t) }) @@ -451,6 +454,7 @@ func TestLedgerBufferClose(t *testing.T) { bsb.dataStore = mockDataStore assert.NoError(t, bsb.PrepareRange(ctx, ledgerRange)) + close(afterPrepareRange) bsb.ledgerBuffer.wg.Wait()