From 48d959e104b0c45b1ae35b5c9f683c952bb6bf37 Mon Sep 17 00:00:00 2001 From: Lazar <12626340+Lazar955@users.noreply.github.com> Date: Fri, 13 Sep 2024 21:21:50 +0200 Subject: [PATCH] chore(*): parallel tests (#44) Speeds up unit tests by 30s --- btcstaking-tracker/btcslasher/bootstrapping_test.go | 2 ++ btcstaking-tracker/btcslasher/slasher_test.go | 2 ++ monitor/btcscanner/btc_scanner_test.go | 2 ++ monitor/liveness_checker_test.go | 2 ++ monitor/query_test.go | 2 ++ reporter/utils_test.go | 1 + retrywrap/retry_test.go | 1 + submitter/poller/poller_test.go | 1 + submitter/relayer/change_address_test.go | 1 + types/btccache_test.go | 1 + types/ckpt_cache_test.go | 1 + types/ckpt_segment_test.go | 1 + types/indexed_block_test.go | 1 + 13 files changed, 18 insertions(+) diff --git a/btcstaking-tracker/btcslasher/bootstrapping_test.go b/btcstaking-tracker/btcslasher/bootstrapping_test.go index dff7061b..153cf27f 100644 --- a/btcstaking-tracker/btcslasher/bootstrapping_test.go +++ b/btcstaking-tracker/btcslasher/bootstrapping_test.go @@ -29,10 +29,12 @@ func FuzzSlasher_Bootstrapping(f *testing.F) { datagen.AddRandomSeedsToFuzzer(f, 10) f.Fuzz(func(t *testing.T, seed int64) { + t.Parallel() r := rand.New(rand.NewSource(seed)) net := &chaincfg.SimNetParams commonCfg := config.DefaultCommonConfig() ctrl := gomock.NewController(t) + defer ctrl.Finish() mockBabylonQuerier := btcslasher.NewMockBabylonQueryClient(ctrl) mockBTCClient := mocks.NewMockBTCClient(ctrl) diff --git a/btcstaking-tracker/btcslasher/slasher_test.go b/btcstaking-tracker/btcslasher/slasher_test.go index e0fb37e3..9c9df040 100644 --- a/btcstaking-tracker/btcslasher/slasher_test.go +++ b/btcstaking-tracker/btcslasher/slasher_test.go @@ -33,10 +33,12 @@ func FuzzSlasher(f *testing.F) { datagen.AddRandomSeedsToFuzzer(f, 10) f.Fuzz(func(t *testing.T, seed int64) { + t.Parallel() r := rand.New(rand.NewSource(seed)) net := &chaincfg.SimNetParams commonCfg := config.DefaultCommonConfig() ctrl := gomock.NewController(t) + defer ctrl.Finish() mockBabylonQuerier := btcslasher.NewMockBabylonQueryClient(ctrl) mockBTCClient := mocks.NewMockBTCClient(ctrl) diff --git a/monitor/btcscanner/btc_scanner_test.go b/monitor/btcscanner/btc_scanner_test.go index 0916cd18..698dfd8b 100644 --- a/monitor/btcscanner/btc_scanner_test.go +++ b/monitor/btcscanner/btc_scanner_test.go @@ -18,6 +18,7 @@ func FuzzBootStrap(f *testing.F) { datagen.AddRandomSeedsToFuzzer(f, 100) f.Fuzz(func(t *testing.T, seed int64) { + t.Parallel() r := rand.New(rand.NewSource(seed)) k := datagen.RandomIntOtherThan(r, 0, 10) // Generate a random number of blocks @@ -26,6 +27,7 @@ func FuzzBootStrap(f *testing.F) { baseHeight := chainIndexedBlocks[0].Height bestHeight := chainIndexedBlocks[len(chainIndexedBlocks)-1].Height ctl := gomock.NewController(t) + defer ctl.Finish() mockBtcClient := mocks.NewMockBTCClient(ctl) confirmedBlocks := chainIndexedBlocks[:numBlocks-k] mockBtcClient.EXPECT().GetBestBlock().Return(nil, uint64(bestHeight), nil) diff --git a/monitor/liveness_checker_test.go b/monitor/liveness_checker_test.go index f8685306..654b1490 100644 --- a/monitor/liveness_checker_test.go +++ b/monitor/liveness_checker_test.go @@ -19,8 +19,10 @@ func FuzzLivenessChecker(f *testing.F) { bbndatagen.AddRandomSeedsToFuzzer(f, 10) f.Fuzz(func(t *testing.T, seed int64) { + t.Parallel() r := rand.New(rand.NewSource(seed)) ctl := gomock.NewController(t) + defer ctl.Finish() mockBabylonClient := monitor.NewMockBabylonQueryClient(ctl) cr := datagen.GenerateRandomCheckpointRecord(r) maxGap := bbndatagen.RandomIntOtherThan(r, 0, 50) + 200 diff --git a/monitor/query_test.go b/monitor/query_test.go index 5d96c3f8..3904d19c 100644 --- a/monitor/query_test.go +++ b/monitor/query_test.go @@ -19,6 +19,7 @@ import ( func FuzzQueryInfoForNextEpoch(f *testing.F) { datagen.AddRandomSeedsToFuzzer(f, 10) f.Fuzz(func(t *testing.T, seed int64) { + t.Parallel() r := rand.New(rand.NewSource(seed)) n := r.Intn(100) + 1 valSet, blsprivkeys := datagen.GenerateValidatorSetWithBLSPrivKeys(n) @@ -26,6 +27,7 @@ func FuzzQueryInfoForNextEpoch(f *testing.F) { e := ckpt.EpochNum ckptWithMeta := &ckpttypes.RawCheckpointWithMeta{Ckpt: ckpt} ctrl := gomock.NewController(t) + defer ctrl.Finish() bbnCli := monitor.NewMockBabylonQueryClient(ctrl) bbnCli.EXPECT().BlsPublicKeyList(gomock.Eq(e), gomock.Nil()).Return( &ckpttypes.QueryBlsPublicKeyListResponse{ diff --git a/reporter/utils_test.go b/reporter/utils_test.go index ab32234e..ec114121 100644 --- a/reporter/utils_test.go +++ b/reporter/utils_test.go @@ -96,6 +96,7 @@ func FuzzProcessCheckpoints(f *testing.F) { datagen.AddRandomSeedsToFuzzer(f, 100) f.Fuzz(func(t *testing.T, seed int64) { + t.Parallel() ctrl := gomock.NewController(t) defer ctrl.Finish() r := rand.New(rand.NewSource(seed)) diff --git a/retrywrap/retry_test.go b/retrywrap/retry_test.go index b0e9be01..05fec78b 100644 --- a/retrywrap/retry_test.go +++ b/retrywrap/retry_test.go @@ -9,6 +9,7 @@ import ( ) func TestWrapDo(t *testing.T) { + t.Parallel() tests := []struct { name string retryableErr error diff --git a/submitter/poller/poller_test.go b/submitter/poller/poller_test.go index 721028a3..51ff3834 100644 --- a/submitter/poller/poller_test.go +++ b/submitter/poller/poller_test.go @@ -25,6 +25,7 @@ func FuzzPollingCheckpoints(f *testing.F) { */ datagen.AddRandomSeedsToFuzzer(f, 10) f.Fuzz(func(t *testing.T, seed int64) { + t.Parallel() r := rand.New(rand.NewSource(seed)) var wg sync.WaitGroup diff --git a/submitter/relayer/change_address_test.go b/submitter/relayer/change_address_test.go index 2029f5ce..6fc9ab4f 100644 --- a/submitter/relayer/change_address_test.go +++ b/submitter/relayer/change_address_test.go @@ -37,6 +37,7 @@ var legacyAddrsStr = []string{ } func TestGetChangeAddress(t *testing.T) { + t.Parallel() submitterAddr, err := sdk.AccAddressFromBech32(submitterAddrStr) require.NoError(t, err) wallet := mocks.NewMockBTCWallet(gomock.NewController(t)) diff --git a/types/btccache_test.go b/types/btccache_test.go index 1658308f..b7f5b787 100644 --- a/types/btccache_test.go +++ b/types/btccache_test.go @@ -19,6 +19,7 @@ func FuzzBtcCache(f *testing.F) { datagen.AddRandomSeedsToFuzzer(f, 100) f.Fuzz(func(t *testing.T, seed int64) { + t.Parallel() r := rand.New(rand.NewSource(seed)) // Create a new cache diff --git a/types/ckpt_cache_test.go b/types/ckpt_cache_test.go index fa184e8d..5233c621 100644 --- a/types/ckpt_cache_test.go +++ b/types/ckpt_cache_test.go @@ -64,6 +64,7 @@ func FuzzCheckpointCache(f *testing.F) { datagen.AddRandomSeedsToFuzzer(f, 100) f.Fuzz(func(t *testing.T, seed int64) { + t.Parallel() r := rand.New(rand.NewSource(seed)) tag := datagen.GenRandomByteArray(r, 4) diff --git a/types/ckpt_segment_test.go b/types/ckpt_segment_test.go index 07854e6b..5e5bd9f1 100644 --- a/types/ckpt_segment_test.go +++ b/types/ckpt_segment_test.go @@ -33,6 +33,7 @@ func toWrappedTx(txHex string) (*btcutil.Tx, error) { } func TestNewCkptSegment(t *testing.T) { + t.Parallel() // The transaction hex corresponds to the tag "bbt0" (in string format) // which translates to the below bytes tag := []byte{98, 98, 116, 48} diff --git a/types/indexed_block_test.go b/types/indexed_block_test.go index edad795f..ae7a868e 100644 --- a/types/indexed_block_test.go +++ b/types/indexed_block_test.go @@ -21,6 +21,7 @@ func FuzzIndexedBlock(f *testing.F) { datagen.AddRandomSeedsToFuzzer(f, 10) f.Fuzz(func(t *testing.T, seed int64) { + t.Parallel() r := rand.New(rand.NewSource(seed)) blocks, _, rawCkpts := vdatagen.GenRandomBlockchainWithBabylonTx(r, 100, 0, 0.4)