Skip to content

Commit c79bbf8

Browse files
committed
refactor: use unittest.WithLock in TestBlockViewIndexLookup
1 parent 57212ff commit c79bbf8

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

storage/operation/headers_test.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"testing"
55
"time"
66

7+
"github.com/jordanschalm/lockctx"
78
"github.com/stretchr/testify/assert"
89
"github.com/stretchr/testify/require"
910

@@ -98,18 +99,15 @@ func TestBlockViewIndexLookup(t *testing.T) {
9899
expected := flow.Identifier{0x01, 0x02, 0x03}
99100

100101
lockManager := storage.NewTestingLockManager()
101-
lctx := lockManager.NewContext()
102-
err := lctx.AcquireLock(storage.LockInsertBlock)
103-
require.NoError(t, err)
104-
defer lctx.Release()
105102

106-
err = db.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error {
107-
return operation.IndexCertifiedBlockByView(lctx, rw, view, expected)
103+
unittest.WithLock(t, lockManager, storage.LockInsertBlock, func(lctx lockctx.Context) error {
104+
return db.WithReaderBatchWriter(func(rw storage.ReaderBatchWriter) error {
105+
return operation.IndexCertifiedBlockByView(lctx, rw, view, expected)
106+
})
108107
})
109-
require.NoError(t, err)
110108

111109
var actual flow.Identifier
112-
err = operation.LookupCertifiedBlockByView(db.Reader(), view, &actual)
110+
err := operation.LookupCertifiedBlockByView(db.Reader(), view, &actual)
113111
require.NoError(t, err)
114112

115113
assert.Equal(t, expected, actual)

0 commit comments

Comments
 (0)