Skip to content

Commit dd925c6

Browse files
AlexHentschelzhangchiqing
authored andcommitted
minor test cleanup:
* renaming a few variable to prevent variable shadowing • removed unnecessary white spaces • removed duplicated instantiation of Lock Manager in testing suite's Setup method plus individual tests.
1 parent 00156e4 commit dd925c6

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

cmd/util/cmd/execution-state-extract/execution_state_extract_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ func TestExtractExecutionState(t *testing.T) {
3737
metr := &metrics.NoopCollector{}
3838

3939
t.Run("missing block->state commitment mapping", func(t *testing.T) {
40-
4140
withDirs(t, func(datadir, execdir, outdir string) {
4241
// Initialize a proper Badger database instead of using empty directory
4342
db := unittest.PebbleDB(t, datadir)
@@ -96,7 +95,6 @@ func TestExtractExecutionState(t *testing.T) {
9695
lockManager := storage.NewTestingLockManager()
9796

9897
withDirs(t, func(datadir, execdir, _ string) {
99-
10098
const (
10199
checkpointDistance = math.MaxInt // A large number to prevent checkpoint creation.
102100
checkpointsToKeep = 1

engine/access/access_test.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,6 @@ func (suite *Suite) TestGetExecutionResultByBlockID() {
636636
// TestGetSealedTransaction tests that transactions status of transaction that belongs to a sealed block
637637
// is reported as sealed
638638
func (suite *Suite) TestGetSealedTransaction() {
639-
lockManager := storage.NewTestingLockManager()
640639
unittest.RunWithBadgerDB(suite.T(), func(db *badger.DB) {
641640
all := bstorage.InitAll(metrics.NewNoopCollector(), db)
642641
en := util.ExecutionStorageLayer(suite.T(), db)
@@ -772,11 +771,11 @@ func (suite *Suite) TestGetSealedTransaction() {
772771
lctx.Release()
773772

774773
fctx := suite.lockManager.NewContext()
775-
defer fctx.Release()
776774
require.NoError(suite.T(), fctx.AcquireLock(storage.LockFinalizeBlock))
777775
require.NoError(suite.T(), bdb.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error {
778776
return operation.IndexFinalizedBlockByHeight(fctx, rw, block.Height, block.ID())
779777
}))
778+
fctx.Release()
780779

781780
suite.sealedBlock = block.ToHeader()
782781

@@ -798,7 +797,7 @@ func (suite *Suite) TestGetSealedTransaction() {
798797
suite.request.On("EntityByID", collection.ID(), mock.Anything).Return()
799798
// 4. Indexer IndexCollection receives the requested collection and all the execution receipts
800799
// Create a lock context for indexing
801-
indexLctx := lockManager.NewContext()
800+
indexLctx := suite.lockManager.NewContext()
802801
lockErr := indexLctx.AcquireLock(storage.LockInsertCollection)
803802
require.NoError(suite.T(), lockErr)
804803
defer indexLctx.Release()
@@ -1149,7 +1148,6 @@ func (suite *Suite) TestGetTransactionResult() {
11491148
// TestExecuteScript tests the three execute Script related calls to make sure that the execution api is called with
11501149
// the correct block id
11511150
func (suite *Suite) TestExecuteScript() {
1152-
lockManager := storage.NewTestingLockManager()
11531151
unittest.RunWithBadgerDB(suite.T(), func(badgerdb *badger.DB) {
11541152
db := badgerimpl.ToDB(badgerdb)
11551153
all := bstorage.InitAll(metrics.NewNoopCollector(), badgerdb)
@@ -1237,7 +1235,7 @@ func (suite *Suite) TestExecuteScript() {
12371235
all.Collections,
12381236
all.Transactions,
12391237
lastFullBlockHeight,
1240-
lockManager,
1238+
suite.lockManager,
12411239
)
12421240

12431241
ingestEng, err := ingestion.New(
@@ -1260,15 +1258,15 @@ func (suite *Suite) TestExecuteScript() {
12601258

12611259
// create a block and a seal pointing to that block
12621260
lastBlock := unittest.BlockWithParentFixture(prevBlock.ToHeader())
1263-
lctx := lockManager.NewContext()
1261+
lctx := suite.lockManager.NewContext()
12641262
require.NoError(suite.T(), lctx.AcquireLock(storage.LockInsertBlock))
12651263
require.NoError(suite.T(), db.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error {
12661264
return all.Blocks.BatchStore(lctx, rw, unittest.ProposalFromBlock(lastBlock))
12671265
}))
12681266
lctx.Release()
12691267
require.NoError(suite.T(), err)
12701268

1271-
fctx := lockManager.NewContext()
1269+
fctx := suite.lockManager.NewContext()
12721270
require.NoError(suite.T(), fctx.AcquireLock(storage.LockFinalizeBlock))
12731271
require.NoError(suite.T(), db.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error {
12741272
return operation.IndexFinalizedBlockByHeight(fctx, rw, lastBlock.Height, lastBlock.ID())
@@ -1285,7 +1283,7 @@ func (suite *Suite) TestExecuteScript() {
12851283
require.NoError(suite.T(), err)
12861284
}
12871285

1288-
fctx2 := lockManager.NewContext()
1286+
fctx2 := suite.lockManager.NewContext()
12891287
require.NoError(suite.T(), fctx2.AcquireLock(storage.LockInsertBlock))
12901288
require.NoError(suite.T(), fctx2.AcquireLock(storage.LockFinalizeBlock))
12911289
require.NoError(suite.T(), db.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error {

engine/execution/pruner/core_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,31 +49,31 @@ func TestLoopPruneExecutionDataFromRootToLatestSealed(t *testing.T) {
4949
// indexed by height
5050
chunks := make([]*verification.VerifiableChunkData, lastFinalizedHeight+2)
5151
parentID := genesis.ID()
52-
lctx := lockManager.NewContext()
53-
require.NoError(t, lctx.AcquireLock(storage.LockInsertBlock))
52+
lctxGenesis := lockManager.NewContext()
53+
require.NoError(t, lctxGenesis.AcquireLock(storage.LockInsertBlock))
5454
require.NoError(t, db.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error {
55-
return blockstore.BatchStore(lctx, rw, &flow.Proposal{Block: *genesis, ProposerSigData: nil})
55+
return blockstore.BatchStore(lctxGenesis, rw, &flow.Proposal{Block: *genesis, ProposerSigData: nil})
5656
}))
57-
lctx.Release()
57+
lctxGenesis.Release()
5858

5959
for i := 1; i <= lastFinalizedHeight; i++ {
6060
chunk, block := unittest.VerifiableChunkDataFixture(0, func(headerBody *flow.HeaderBody) {
6161
headerBody.Height = uint64(i)
6262
headerBody.ParentID = parentID
6363
})
6464
chunks[i] = chunk // index by height
65-
lctx := lockManager.NewContext()
66-
require.NoError(t, lctx.AcquireLock(storage.LockInsertBlock))
65+
lctxBlock := lockManager.NewContext()
66+
require.NoError(t, lctxBlock.AcquireLock(storage.LockInsertBlock))
6767
require.NoError(t, db.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error {
68-
return blockstore.BatchStore(lctx, rw, unittest.ProposalFromBlock(block))
68+
return blockstore.BatchStore(lctxBlock, rw, unittest.ProposalFromBlock(block))
6969
}))
70-
lctx.Release()
71-
lctx = lockManager.NewContext()
72-
require.NoError(t, lctx.AcquireLock(storage.LockFinalizeBlock))
70+
lctxBlock.Release()
71+
lctxFinality := lockManager.NewContext()
72+
require.NoError(t, lctxFinality.AcquireLock(storage.LockFinalizeBlock))
7373
require.NoError(t, db.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error {
74-
return operation.IndexFinalizedBlockByHeight(lctx, rw, chunk.Header.Height, chunk.Header.ID())
74+
return operation.IndexFinalizedBlockByHeight(lctxFinality, rw, chunk.Header.Height, chunk.Header.ID())
7575
}))
76-
lctx.Release()
76+
lctxFinality.Release()
7777
require.NoError(t, results.Store(chunk.Result))
7878
require.NoError(t, results.Index(chunk.Result.BlockID, chunk.Result.ID()))
7979
require.NoError(t, chunkDataPacks.Store([]*flow.ChunkDataPack{chunk.ChunkDataPack}))

0 commit comments

Comments
 (0)