@@ -3,6 +3,7 @@ package store_test
33import (
44 "testing"
55
6+ "github.com/jordanschalm/lockctx"
67 "github.com/onflow/flow-go/storage/operation"
78 "github.com/onflow/flow-go/storage/operation/dbtest"
89 "github.com/onflow/flow-go/storage/store"
@@ -63,25 +64,19 @@ func TestHeaderIndexByViewAndRetrieve(t *testing.T) {
6364 proposal := unittest .ProposalFixture ()
6465 block := proposal .Block
6566
66- lctx := lockManager .NewContext ()
67- err := lctx .AcquireLock (storage .LockInsertBlock )
68- require .NoError (t , err )
69- defer lctx .Release ()
70-
7167 // store block which will also store header
72- err = db .WithReaderBatchWriter (func (rw storage.ReaderBatchWriter ) error {
73- return blocks .BatchStore (lctx , rw , proposal )
68+ unittest .WithLock (t , lockManager , storage .LockInsertBlock , func (lctx lockctx.Context ) error {
69+ return db .WithReaderBatchWriter (func (rw storage.ReaderBatchWriter ) error {
70+ return blocks .BatchStore (lctx , rw , proposal )
71+ })
7472 })
75- require .NoError (t , err )
7673
77- lctx2 := lockManager . NewContext ()
78- require . NoError ( t , lctx2 . AcquireLock ( storage .LockFinalizeBlock ))
79- // index the header
80- err = db . WithReaderBatchWriter ( func ( rw storage. ReaderBatchWriter ) error {
81- return operation . IndexCertifiedBlockByView ( lctx2 , rw , block . View , block . ID () )
74+ unittest . WithLock ( t , lockManager , storage . LockInsertBlock , func ( lctx lockctx. Context ) error {
75+ return db . WithReaderBatchWriter ( func ( rw storage.ReaderBatchWriter ) error {
76+ // index the header
77+ return operation . IndexCertifiedBlockByView ( lctx , rw , block . View , block . ID ())
78+ } )
8279 })
83- lctx2 .Release ()
84- require .NoError (t , err )
8580
8681 // retrieve header by view
8782 actual , err := headers .ByView (block .View )
0 commit comments