Skip to content

Commit

Permalink
chore(*): parallel tests (#44)
Browse files Browse the repository at this point in the history
Speeds up unit tests by 30s
  • Loading branch information
Lazar955 authored Sep 13, 2024
1 parent 7233f1b commit 48d959e
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions btcstaking-tracker/btcslasher/bootstrapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions btcstaking-tracker/btcslasher/slasher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions monitor/btcscanner/btc_scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions monitor/liveness_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions monitor/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ 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)
ckpt := datagen.GenerateLegitimateRawCheckpoint(r, blsprivkeys)
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{
Expand Down
1 change: 1 addition & 0 deletions reporter/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions retrywrap/retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

func TestWrapDo(t *testing.T) {
t.Parallel()
tests := []struct {
name string
retryableErr error
Expand Down
1 change: 1 addition & 0 deletions submitter/poller/poller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions submitter/relayer/change_address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions types/btccache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions types/ckpt_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions types/ckpt_segment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
1 change: 1 addition & 0 deletions types/indexed_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 48d959e

Please sign in to comment.