Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enable paralleltest lint check in package postage #4913

Merged
merged 4 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,14 @@ issues:
- linters:
- forbidigo
path: cmd/bee/cmd
text: "use of `fmt.Print" ## allow fmt.Print in cmd directory
text: "use of `fmt.Print" ## allow fmt.Print in cmd directory
- linters:
- dogsled
path: pkg/api/(.+)_test\.go # temporally disable dogsled in api test files
- linters:
- dogsled
path: pkg/pushsync/(.+)_test\.go # temporally disable dogsled in pushsync test files
# temporally disable paralleltest in following packages
- linters:
- paralleltest
path: pkg/postage
- linters:
- paralleltest
path: pkg/log
Expand Down
2 changes: 2 additions & 0 deletions pkg/postage/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
// TestBatchMarshalling tests the idempotence of binary marshal/unmarshal for a
// Batch.
func TestBatchMarshalling(t *testing.T) {
t.Parallel()

a := postagetesting.MustNewBatch()
buf, err := a.MarshalBinary()
if err != nil {
Expand Down
20 changes: 19 additions & 1 deletion pkg/postage/batchservice/batchservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ func (m *mockBatchListener) HandleDepthIncrease(_ []byte, _ uint8) {

var _ postage.BatchEventListener = (*mockBatchListener)(nil)

func TestBatchServiceCreate_FLAKY(t *testing.T) {
func TestBatchServiceCreate(t *testing.T) {
t.Parallel()

testChainState := postagetesting.NewChainState()

validateNoBatch := func(t *testing.T, testBatch *postage.Batch, st *mock.BatchStore) {
Expand Down Expand Up @@ -240,6 +242,8 @@ func TestBatchServiceCreate_FLAKY(t *testing.T) {
}

func TestBatchServiceTopUp(t *testing.T) {
t.Parallel()

testBatch := postagetesting.MustNewBatch()
testNormalisedBalance := big.NewInt(2000000000000)
testTopUpAmount := big.NewInt(1000)
Expand Down Expand Up @@ -341,6 +345,8 @@ func TestBatchServiceTopUp(t *testing.T) {
}

func TestBatchServiceUpdateDepth(t *testing.T) {
t.Parallel()

const testNewDepth = 30
testNormalisedBalance := big.NewInt(2000000000000)
testBatch := postagetesting.MustNewBatch()
Expand Down Expand Up @@ -443,6 +449,8 @@ func TestBatchServiceUpdateDepth(t *testing.T) {
}

func TestBatchServiceUpdatePrice(t *testing.T) {
t.Parallel()

testChainState := postagetesting.NewChainState()
testChainState.CurrentPrice = big.NewInt(100000)
testNewPrice := big.NewInt(20000000)
Expand Down Expand Up @@ -477,6 +485,8 @@ func TestBatchServiceUpdatePrice(t *testing.T) {
})
}
func TestBatchServiceUpdateBlockNumber(t *testing.T) {
t.Parallel()

testChainState := &postage.ChainState{
Block: 1,
CurrentPrice: big.NewInt(100),
Expand All @@ -501,6 +511,8 @@ func TestBatchServiceUpdateBlockNumber(t *testing.T) {
}

func TestTransactionOk(t *testing.T) {
t.Parallel()

svc, store, s := newTestStoreAndService(t)
if err := svc.Start(context.Background(), 10, nil); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -528,6 +540,8 @@ func TestTransactionOk(t *testing.T) {
}

func TestTransactionError(t *testing.T) {
t.Parallel()

svc, store, s := newTestStoreAndService(t)
if err := svc.Start(context.Background(), 10, nil); err != nil {
t.Fatal(err)
Expand All @@ -551,6 +565,8 @@ func TestTransactionError(t *testing.T) {
}

func TestChecksum(t *testing.T) {
t.Parallel()

s := mocks.NewStateStore()
store := mock.New()
mockHash := &hs{}
Expand All @@ -572,6 +588,8 @@ func TestChecksum(t *testing.T) {
}

func TestChecksumResync(t *testing.T) {
t.Parallel()

s := mocks.NewStateStore()
store := mock.New()
mockHash := &hs{}
Expand Down
6 changes: 6 additions & 0 deletions pkg/postage/batchstore/mock/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
)

func TestBatchStore(t *testing.T) {
t.Parallel()

const testCnt = 3

testBatch := postagetesting.MustNewBatch(
Expand Down Expand Up @@ -54,6 +56,8 @@ func TestBatchStore(t *testing.T) {
}

func TestBatchStorePutChainState(t *testing.T) {
t.Parallel()

const testCnt = 3

testChainState := postagetesting.NewChainState()
Expand All @@ -74,6 +78,8 @@ func TestBatchStorePutChainState(t *testing.T) {
}

func TestBatchStoreWithBatch(t *testing.T) {
t.Parallel()

testBatch := postagetesting.MustNewBatch()
batchStore := mock.New(
mock.WithBatch(testBatch),
Expand Down
17 changes: 12 additions & 5 deletions pkg/postage/batchstore/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var noopEvictFn = func([]byte) error { return nil }
const defaultCapacity = 2 ^ 22

func TestBatchStore_Get(t *testing.T) {
t.Parallel()
testBatch := postagetest.MustNewBatch()

stateStore := mock.NewStateStore()
Expand All @@ -42,6 +43,7 @@ func TestBatchStore_Get(t *testing.T) {
}

func TestBatchStore_Iterate(t *testing.T) {
t.Parallel()
testBatch := postagetest.MustNewBatch()
key := batchstore.BatchKey(testBatch.ID)

Expand All @@ -63,6 +65,7 @@ func TestBatchStore_Iterate(t *testing.T) {
}

func TestBatchStore_IterateStopsEarly(t *testing.T) {
t.Parallel()
testBatch1 := postagetest.MustNewBatch()
key1 := batchstore.BatchKey(testBatch1.ID)

Expand Down Expand Up @@ -113,6 +116,7 @@ func TestBatchStore_IterateStopsEarly(t *testing.T) {
}

func TestBatchStore_SaveAndUpdate(t *testing.T) {
t.Parallel()
testBatch := postagetest.MustNewBatch()
key := batchstore.BatchKey(testBatch.ID)

Expand Down Expand Up @@ -157,6 +161,7 @@ func TestBatchStore_SaveAndUpdate(t *testing.T) {
}

func TestBatchStore_GetChainState(t *testing.T) {
t.Parallel()
testChainState := postagetest.NewChainState()

stateStore := mock.NewStateStore()
Expand All @@ -171,6 +176,7 @@ func TestBatchStore_GetChainState(t *testing.T) {
}

func TestBatchStore_PutChainState(t *testing.T) {
t.Parallel()
testChainState := postagetest.NewChainState()

stateStore := mock.NewStateStore()
Expand All @@ -183,6 +189,7 @@ func TestBatchStore_PutChainState(t *testing.T) {
}

func TestBatchStore_Reset(t *testing.T) {
t.Parallel()
testChainState := postagetest.NewChainState()
testBatch := postagetest.MustNewBatch(
postagetest.WithValue(15),
Expand Down Expand Up @@ -236,7 +243,7 @@ type testBatch struct {
// TestBatchSave adds batches to the batchstore, and after each batch, checks
// the reserve state radius.
func TestBatchSave(t *testing.T) {

t.Parallel()
totalCapacity := batchstore.Exp2(5)

defaultDepth := uint8(8)
Expand Down Expand Up @@ -310,7 +317,7 @@ func TestBatchSave(t *testing.T) {
// TestBatchUpdate adds an initial group of batches to the batchstore and one by one
// updates their depth and value fields while checking the batchstore radius values.
func TestBatchUpdate(t *testing.T) {

t.Parallel()
totalCapacity := batchstore.Exp2(5)

defaultDepth := uint8(8)
Expand Down Expand Up @@ -406,7 +413,7 @@ func TestBatchUpdate(t *testing.T) {
// TestPutChainState add a group of batches to the batchstore, and after updating the chainstate,
// checks the batchstore radius reflects the updates.
func TestPutChainState(t *testing.T) {

t.Parallel()
totalCapacity := batchstore.Exp2(5)

defaultDepth := uint8(8)
Expand Down Expand Up @@ -481,6 +488,7 @@ func TestPutChainState(t *testing.T) {
}

func TestBatchExpiry(t *testing.T) {
t.Parallel()
store := setupBatchStore(t, defaultCapacity)

batch := postagetest.MustNewBatch(
Expand Down Expand Up @@ -512,6 +520,7 @@ func TestBatchExpiry(t *testing.T) {
}

func TestUnexpiredBatch(t *testing.T) {
t.Parallel()
store := setupBatchStore(t, defaultCapacity)

batch := postagetest.MustNewBatch(
Expand Down Expand Up @@ -571,7 +580,6 @@ func setupBatchStore(t *testing.T, capacity int) postage.Storer {
}

func checkState(t *testing.T, name string, store postage.Storer, radius uint8) {

t.Helper()

if radius != store.Radius() {
Expand All @@ -580,7 +588,6 @@ func checkState(t *testing.T, name string, store postage.Storer, radius uint8) {
}

func addBatch(t *testing.T, s postage.Storer, depth uint8, value int) *postage.Batch {

t.Helper()

batch := postagetest.MustNewBatch(
Expand Down
4 changes: 4 additions & 0 deletions pkg/postage/listener/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func toBatchBlock(block uint64) uint64 {
}

func TestListener(t *testing.T) {
t.Parallel()

const (
blockNumber = uint64(500)
timeout = 5 * time.Second
Expand Down Expand Up @@ -417,6 +419,8 @@ func TestListener(t *testing.T) {
}

func TestListenerBatchState(t *testing.T) {
t.Parallel()

ev := newEventUpdaterMock()
mf := newMockFilterer()

Expand Down
6 changes: 6 additions & 0 deletions pkg/postage/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
// TestSaveLoad tests the idempotence of saving and loading the postage.Service
// with all the active stamp issuers.
func TestSaveLoad(t *testing.T) {
t.Parallel()

store := inmemstore.New()
defer store.Close()
pstore := pstoremock.New()
Expand Down Expand Up @@ -74,6 +76,8 @@ func TestSaveLoad(t *testing.T) {
}

func TestGetStampIssuer(t *testing.T) {
t.Parallel()

store := inmemstore.New()
defer store.Close()
chainID := int64(0)
Expand Down Expand Up @@ -208,6 +212,8 @@ func TestGetStampIssuer(t *testing.T) {
}

func TestSetExpired(t *testing.T) {
t.Parallel()

store := inmemstore.New()
testutil.CleanupCloser(t, store)

Expand Down
8 changes: 8 additions & 0 deletions pkg/postage/stamp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (

// TestStampMarshalling tests the idempotence of binary marshal/unmarshals for Stamps.
func TestStampMarshalling(t *testing.T) {
t.Parallel()

sExp := postagetesting.MustNewStamp()
buf, _ := sExp.MarshalBinary()
if len(buf) != postage.StampSize {
Expand All @@ -35,6 +37,8 @@ func TestStampMarshalling(t *testing.T) {

// TestStampMarshalling tests the idempotence of binary marshal/unmarshals for Stamps.
func TestStampJsonMarshalling(t *testing.T) {
t.Parallel()

sExp := postagetesting.MustNewStamp()

b, err := json.Marshal(sExp)
Expand Down Expand Up @@ -70,6 +74,8 @@ func compareStamps(t *testing.T, s1, s2 *postage.Stamp) {

// TestStampIndexMarshalling tests the idempotence of stamp index serialisation.
func TestStampIndexMarshalling(t *testing.T) {
t.Parallel()

var (
expBucket uint32 = 11789
expIndex uint32 = 199999
Expand All @@ -85,6 +91,8 @@ func TestStampIndexMarshalling(t *testing.T) {
}

func TestValidStamp(t *testing.T) {
t.Parallel()

privKey, err := crypto.GenerateSecp256k1Key()
if err != nil {
t.Fatal(err)
Expand Down
2 changes: 2 additions & 0 deletions pkg/postage/stamper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (

// TestStamperStamping tests if the stamp created by the stamper is valid.
func TestStamperStamping(t *testing.T) {
t.Parallel()

privKey, err := crypto.GenerateSecp256k1Key()
if err != nil {
t.Fatal(err)
Expand Down
2 changes: 2 additions & 0 deletions pkg/postage/stampissuer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (

// TestStampIssuerMarshalling tests the idempotence of binary marshal/unmarshal.
func TestStampIssuerMarshalling(t *testing.T) {
t.Parallel()

want := newTestStampIssuer(t, 1000)
buf, err := want.MarshalBinary()
if err != nil {
Expand Down
Loading