From 337ea0db6398dbf9fd780a9a664cc65081831bfd Mon Sep 17 00:00:00 2001 From: Calin Martinconi Date: Thu, 28 Nov 2024 11:21:43 +0200 Subject: [PATCH] fix: enable paralleltest lint check in package postage (#4913) --- .golangci.yml | 3 --- pkg/postage/batch_test.go | 2 ++ pkg/postage/batchservice/batchservice_test.go | 20 ++++++++++++++++++- pkg/postage/batchstore/mock/store_test.go | 6 ++++++ pkg/postage/batchstore/store_test.go | 17 +++++++++++----- pkg/postage/listener/listener_test.go | 4 ++++ pkg/postage/service_test.go | 6 ++++++ pkg/postage/stamp_test.go | 8 ++++++++ pkg/postage/stamper_test.go | 2 ++ pkg/postage/stampissuer_test.go | 2 ++ 10 files changed, 61 insertions(+), 9 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index cd8c61c8961..4f07d6fa978 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -70,9 +70,6 @@ issues: - 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 diff --git a/pkg/postage/batch_test.go b/pkg/postage/batch_test.go index e7b419d6e02..590ee635c97 100644 --- a/pkg/postage/batch_test.go +++ b/pkg/postage/batch_test.go @@ -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 { diff --git a/pkg/postage/batchservice/batchservice_test.go b/pkg/postage/batchservice/batchservice_test.go index 0fd2bfe4c14..9500acaba28 100644 --- a/pkg/postage/batchservice/batchservice_test.go +++ b/pkg/postage/batchservice/batchservice_test.go @@ -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) { @@ -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) @@ -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() @@ -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) @@ -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), @@ -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) @@ -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) @@ -551,6 +565,8 @@ func TestTransactionError(t *testing.T) { } func TestChecksum(t *testing.T) { + t.Parallel() + s := mocks.NewStateStore() store := mock.New() mockHash := &hs{} @@ -572,6 +588,8 @@ func TestChecksum(t *testing.T) { } func TestChecksumResync(t *testing.T) { + t.Parallel() + s := mocks.NewStateStore() store := mock.New() mockHash := &hs{} diff --git a/pkg/postage/batchstore/mock/store_test.go b/pkg/postage/batchstore/mock/store_test.go index 824988f38f0..d376c359819 100644 --- a/pkg/postage/batchstore/mock/store_test.go +++ b/pkg/postage/batchstore/mock/store_test.go @@ -14,6 +14,8 @@ import ( ) func TestBatchStore(t *testing.T) { + t.Parallel() + const testCnt = 3 testBatch := postagetesting.MustNewBatch( @@ -54,6 +56,8 @@ func TestBatchStore(t *testing.T) { } func TestBatchStorePutChainState(t *testing.T) { + t.Parallel() + const testCnt = 3 testChainState := postagetesting.NewChainState() @@ -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), diff --git a/pkg/postage/batchstore/store_test.go b/pkg/postage/batchstore/store_test.go index 880b22ab4d2..603dd24f398 100644 --- a/pkg/postage/batchstore/store_test.go +++ b/pkg/postage/batchstore/store_test.go @@ -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() @@ -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) @@ -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) @@ -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) @@ -157,6 +161,7 @@ func TestBatchStore_SaveAndUpdate(t *testing.T) { } func TestBatchStore_GetChainState(t *testing.T) { + t.Parallel() testChainState := postagetest.NewChainState() stateStore := mock.NewStateStore() @@ -171,6 +176,7 @@ func TestBatchStore_GetChainState(t *testing.T) { } func TestBatchStore_PutChainState(t *testing.T) { + t.Parallel() testChainState := postagetest.NewChainState() stateStore := mock.NewStateStore() @@ -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), @@ -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) @@ -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) @@ -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) @@ -481,6 +488,7 @@ func TestPutChainState(t *testing.T) { } func TestBatchExpiry(t *testing.T) { + t.Parallel() store := setupBatchStore(t, defaultCapacity) batch := postagetest.MustNewBatch( @@ -512,6 +520,7 @@ func TestBatchExpiry(t *testing.T) { } func TestUnexpiredBatch(t *testing.T) { + t.Parallel() store := setupBatchStore(t, defaultCapacity) batch := postagetest.MustNewBatch( @@ -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() { @@ -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( diff --git a/pkg/postage/listener/listener_test.go b/pkg/postage/listener/listener_test.go index 43c8675883d..e3ee957a3e8 100644 --- a/pkg/postage/listener/listener_test.go +++ b/pkg/postage/listener/listener_test.go @@ -45,6 +45,8 @@ func toBatchBlock(block uint64) uint64 { } func TestListener(t *testing.T) { + t.Parallel() + const ( blockNumber = uint64(500) timeout = 5 * time.Second @@ -417,6 +419,8 @@ func TestListener(t *testing.T) { } func TestListenerBatchState(t *testing.T) { + t.Parallel() + ev := newEventUpdaterMock() mf := newMockFilterer() diff --git a/pkg/postage/service_test.go b/pkg/postage/service_test.go index f432565fb4a..1ae9dfd1b46 100644 --- a/pkg/postage/service_test.go +++ b/pkg/postage/service_test.go @@ -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() @@ -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) @@ -208,6 +212,8 @@ func TestGetStampIssuer(t *testing.T) { } func TestSetExpired(t *testing.T) { + t.Parallel() + store := inmemstore.New() testutil.CleanupCloser(t, store) diff --git a/pkg/postage/stamp_test.go b/pkg/postage/stamp_test.go index 948e5311686..c897faffdfe 100644 --- a/pkg/postage/stamp_test.go +++ b/pkg/postage/stamp_test.go @@ -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 { @@ -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) @@ -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 @@ -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) diff --git a/pkg/postage/stamper_test.go b/pkg/postage/stamper_test.go index 4069a6daac6..383c534a0c4 100644 --- a/pkg/postage/stamper_test.go +++ b/pkg/postage/stamper_test.go @@ -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) diff --git a/pkg/postage/stampissuer_test.go b/pkg/postage/stampissuer_test.go index 460e1f20458..5e7bfa71cbc 100644 --- a/pkg/postage/stampissuer_test.go +++ b/pkg/postage/stampissuer_test.go @@ -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 {