|  | 
| 7 | 7 | 	"time" | 
| 8 | 8 | 
 | 
| 9 | 9 | 	"github.com/cockroachdb/pebble/v2" | 
|  | 10 | +	"github.com/jordanschalm/lockctx" | 
| 10 | 11 | 	"github.com/stretchr/testify/require" | 
| 11 | 12 | 
 | 
| 12 | 13 | 	"github.com/onflow/flow-go/model/flow" | 
| @@ -46,35 +47,34 @@ func TestLoopPruneExecutionDataFromRootToLatestSealed(t *testing.T) { | 
| 46 | 47 | 		// indexed by height | 
| 47 | 48 | 		chunks := make([]*verification.VerifiableChunkData, lastFinalizedHeight+2) | 
| 48 | 49 | 		parentID := genesis.ID() | 
| 49 |  | -		lctxGenesis := lockManager.NewContext() | 
| 50 |  | -		require.NoError(t, lctxGenesis.AcquireLock(storage.LockInsertBlock)) | 
| 51 |  | -		require.NoError(t, db.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error { | 
| 52 |  | -			// By convention, root block has no proposer signature - implementation has to handle this edge case | 
| 53 |  | -			return blockstore.BatchStore(lctxGenesis, rw, &flow.Proposal{Block: *genesis, ProposerSigData: nil}) | 
| 54 |  | -		})) | 
| 55 |  | -		lctxGenesis.Release() | 
|  | 50 | +		unittest.WithLock(t, lockManager, storage.LockInsertBlock, func(lctx lockctx.Context) error { | 
|  | 51 | +			return db.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error { | 
|  | 52 | +				// By convention, root block has no proposer signature - implementation has to handle this edge case | 
|  | 53 | +				return blockstore.BatchStore(lctx, rw, &flow.Proposal{Block: *genesis, ProposerSigData: nil}) | 
|  | 54 | +			}) | 
|  | 55 | +		}) | 
| 56 | 56 | 
 | 
| 57 | 57 | 		for i := 1; i <= lastFinalizedHeight; i++ { | 
| 58 | 58 | 			chunk, block := unittest.VerifiableChunkDataFixture(0, func(headerBody *flow.HeaderBody) { | 
| 59 | 59 | 				headerBody.Height = uint64(i) | 
| 60 | 60 | 				headerBody.ParentID = parentID | 
| 61 | 61 | 			}) | 
| 62 | 62 | 			chunks[i] = chunk // index by height | 
| 63 |  | -			lctxBlock := lockManager.NewContext() | 
| 64 |  | -			require.NoError(t, lctxBlock.AcquireLock(storage.LockInsertBlock)) | 
| 65 |  | -			require.NoError(t, db.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error { | 
| 66 |  | -				return blockstore.BatchStore(lctxBlock, rw, unittest.ProposalFromBlock(block)) | 
| 67 |  | -			})) | 
| 68 |  | -			lctxBlock.Release() | 
| 69 |  | -			lctxFinality := lockManager.NewContext() | 
| 70 |  | -			require.NoError(t, lctxFinality.AcquireLock(storage.LockFinalizeBlock)) | 
| 71 |  | -			require.NoError(t, db.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error { | 
| 72 |  | -				return operation.IndexFinalizedBlockByHeight(lctxFinality, rw, chunk.Header.Height, chunk.Header.ID()) | 
| 73 |  | -			})) | 
| 74 |  | -			lctxFinality.Release() | 
|  | 63 | +			unittest.WithLock(t, lockManager, storage.LockInsertBlock, func(lctx lockctx.Context) error { | 
|  | 64 | +				return db.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error { | 
|  | 65 | +					return blockstore.BatchStore(lctx, rw, unittest.ProposalFromBlock(block)) | 
|  | 66 | +				}) | 
|  | 67 | +			}) | 
|  | 68 | +			unittest.WithLock(t, lockManager, storage.LockFinalizeBlock, func(lctx lockctx.Context) error { | 
|  | 69 | +				return db.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error { | 
|  | 70 | +					return operation.IndexFinalizedBlockByHeight(lctx, rw, chunk.Header.Height, chunk.Header.ID()) | 
|  | 71 | +				}) | 
|  | 72 | +			}) | 
| 75 | 73 | 			require.NoError(t, results.Store(chunk.Result)) | 
| 76 | 74 | 			require.NoError(t, results.Index(chunk.Result.BlockID, chunk.Result.ID())) | 
| 77 |  | -			require.NoError(t, chunkDataPacks.Store([]*flow.ChunkDataPack{chunk.ChunkDataPack})) | 
|  | 75 | +			unittest.WithLock(t, lockManager, storage.LockInsertChunkDataPack, func(lctx lockctx.Context) error { | 
|  | 76 | +				return chunkDataPacks.Store(lctx, []*flow.ChunkDataPack{chunk.ChunkDataPack}) | 
|  | 77 | +			}) | 
| 78 | 78 | 			_, storeErr := collections.Store(chunk.ChunkDataPack.Collection) | 
| 79 | 79 | 			require.NoError(t, storeErr) | 
| 80 | 80 | 			// verify that chunk data pack fixture can be found by the result | 
|  | 
0 commit comments