Skip to content

Commit

Permalink
fix data race in TestLedgerBufferClose
Browse files Browse the repository at this point in the history
  • Loading branch information
tamirms committed May 7, 2024
1 parent 010e254 commit 241c802
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ingest/ledgerbackend/buffered_storage_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,16 +441,20 @@ 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)
})

bsb.dataStore = mockDataStore

assert.NoError(t, bsb.PrepareRange(ctx, ledgerRange))
close(afterPrepareRange)

bsb.ledgerBuffer.wg.Wait()

Expand Down

0 comments on commit 241c802

Please sign in to comment.