Skip to content

Commit

Permalink
parallel tests
Browse files Browse the repository at this point in the history
  • Loading branch information
faddat committed Jun 19, 2023
1 parent e857029 commit 69933c3
Show file tree
Hide file tree
Showing 78 changed files with 161 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ linters:
- ineffassign
- misspell
- nakedret
- paralleltest
- staticcheck
- tparallel
- thelper
- stylecheck
- revive
Expand Down
8 changes: 8 additions & 0 deletions cmd/build_test_matrix/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ const (
)

func TestGetGithubActionMatrixForTests(t *testing.T) {
t.Parallel()
t.Run("empty dir does not fail", func(t *testing.T) {
t.Parallel()
testingDir := t.TempDir()
_, err := getGithubActionMatrixForTests(testingDir, "", "", nil)
assert.NoError(t, err)
})

t.Run("only test functions are picked up", func(t *testing.T) {
t.Parallel()
testingDir := t.TempDir()
createFileWithTestSuiteAndTests(t, "FeeMiddlewareTestSuite", "TestA", "TestB", testingDir, goTestFileNameOne)

Expand All @@ -46,6 +49,7 @@ func TestGetGithubActionMatrixForTests(t *testing.T) {
})

t.Run("all files are picked up", func(t *testing.T) {
t.Parallel()
testingDir := t.TempDir()
createFileWithTestSuiteAndTests(t, "FeeMiddlewareTestSuite", "TestA", "TestB", testingDir, goTestFileNameOne)
createFileWithTestSuiteAndTests(t, "TransferTestSuite", "TestC", "TestD", testingDir, goTestFileNameTwo)
Expand Down Expand Up @@ -78,6 +82,7 @@ func TestGetGithubActionMatrixForTests(t *testing.T) {
})

t.Run("single test can be specified", func(t *testing.T) {
t.Parallel()
testingDir := t.TempDir()
createFileWithTestSuiteAndTests(t, "FeeMiddlewareTestSuite", "TestA", "TestB", testingDir, goTestFileNameOne)
createFileWithTestSuiteAndTests(t, "TransferTestSuite", "TestC", "TestD", testingDir, goTestFileNameTwo)
Expand All @@ -98,6 +103,7 @@ func TestGetGithubActionMatrixForTests(t *testing.T) {
})

t.Run("error if single test doesn't exist", func(t *testing.T) {
t.Parallel()
testingDir := t.TempDir()
createFileWithTestSuiteAndTests(t, "FeeMiddlewareTestSuite", "TestA", "TestB", testingDir, goTestFileNameOne)

Expand All @@ -106,6 +112,7 @@ func TestGetGithubActionMatrixForTests(t *testing.T) {
})

t.Run("non test files are not picked up", func(t *testing.T) {
t.Parallel()
testingDir := t.TempDir()
createFileWithTestSuiteAndTests(t, "FeeMiddlewareTestSuite", "TestA", "TestB", testingDir, nonTestFile)

Expand All @@ -115,6 +122,7 @@ func TestGetGithubActionMatrixForTests(t *testing.T) {
})

t.Run("fails when there are multiple suite runs", func(t *testing.T) {
t.Parallel()
testingDir := t.TempDir()
createFileWithTestSuiteAndTests(t, "FeeMiddlewareTestSuite", "TestA", "TestB", testingDir, nonTestFile)

Expand Down
2 changes: 2 additions & 0 deletions internal/collections/collections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

func TestContainsString(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
haystack []string
Expand All @@ -26,6 +27,7 @@ func TestContainsString(t *testing.T) {
}

func TestContainsInt(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
haystack []int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type InterchainAccountsTestSuite struct {
}

func TestICATestSuite(t *testing.T) {
t.Parallel()
suite.Run(t, new(InterchainAccountsTestSuite))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func RegisterInterchainAccount(endpoint *ibctesting.Endpoint, owner string) erro
}

func TestKeeperTestSuite(t *testing.T) {
t.Parallel()
suite.Run(t, new(KeeperTestSuite))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (suite *MigrationsTestSuite) RegisterInterchainAccount(endpoint *ibctesting
}

func TestKeeperTestSuite(t *testing.T) {
t.Parallel()
suite.Run(t, new(MigrationsTestSuite))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
)

func TestMsgRegisterInterchainAccountValidateBasic(t *testing.T) {
t.Parallel()
var msg *types.MsgRegisterInterchainAccount

testCases := []struct {
Expand Down Expand Up @@ -88,6 +89,7 @@ func TestMsgRegisterInterchainAccountValidateBasic(t *testing.T) {
}

func TestMsgRegisterInterchainAccountGetSigners(t *testing.T) {
t.Parallel()
expSigner, err := sdk.AccAddressFromBech32(ibctesting.TestAccAddress)
require.NoError(t, err)

Expand All @@ -96,6 +98,7 @@ func TestMsgRegisterInterchainAccountGetSigners(t *testing.T) {
}

func TestMsgSendTxValidateBasic(t *testing.T) {
t.Parallel()
var msg *types.MsgSendTx

testCases := []struct {
Expand Down Expand Up @@ -181,6 +184,7 @@ func TestMsgSendTxValidateBasic(t *testing.T) {
}

func TestMsgSendTxGetSigners(t *testing.T) {
t.Parallel()
expSigner, err := sdk.AccAddressFromBech32(ibctesting.TestAccAddress)
require.NoError(t, err)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const bankSendMessage = `{
var multiMsg = fmt.Sprintf("[ %s, %s ]", msgDelegateMessage, bankSendMessage)

func TestGeneratePacketData(t *testing.T) {
t.Parallel()
t.Helper()
tests := []struct {
name string
Expand Down Expand Up @@ -110,6 +111,7 @@ func TestGeneratePacketData(t *testing.T) {
cdc := codec.NewProtoCodec(ir)

t.Run(tc.name, func(t *testing.T) {
t.Parallel()
bz, err := generatePacketData(cdc, []byte(tc.message), tc.memo)

if tc.expectedPass {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type InterchainAccountsTestSuite struct {
}

func TestICATestSuite(t *testing.T) {
t.Parallel()
suite.Run(t, new(InterchainAccountsTestSuite))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func RegisterInterchainAccount(endpoint *ibctesting.Endpoint, owner string) erro
}

func TestKeeperTestSuite(t *testing.T) {
t.Parallel()
suite.Run(t, new(KeeperTestSuite))
}

Expand Down
4 changes: 4 additions & 0 deletions modules/apps/27-interchain-accounts/host/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

func TestMsgUpdateParamsValidateBasic(t *testing.T) {
t.Parallel()
var msg *types.MsgUpdateParams

testCases := []struct {
Expand Down Expand Up @@ -50,7 +51,9 @@ func TestMsgUpdateParamsValidateBasic(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
tc.malleate()

err := msg.ValidateBasic()
Expand All @@ -64,6 +67,7 @@ func TestMsgUpdateParamsValidateBasic(t *testing.T) {
}

func TestMsgUpdateParamsGetSigners(t *testing.T) {
t.Parallel()
authority := sdk.AccAddress("authority")
msg := types.MsgUpdateParams{
Authority: authority.String(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

func TestValidateParams(t *testing.T) {
t.Parallel()
require.NoError(t, types.DefaultParams().Validate())
require.NoError(t, types.NewParams(false, []string{}).Validate())
require.Error(t, types.NewParams(true, []string{""}).Validate())
Expand Down
1 change: 1 addition & 0 deletions modules/apps/27-interchain-accounts/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type InterchainAccountsTestSuite struct {
}

func TestICATestSuite(t *testing.T) {
t.Parallel()
suite.Run(t, new(InterchainAccountsTestSuite))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
)

func TestDecodeStore(t *testing.T) {
t.Parallel()
var (
owner = "owner"
channelID = ibctesting.FirstChannelID
Expand Down Expand Up @@ -54,6 +55,7 @@ func TestDecodeStore(t *testing.T) {
for i, tt := range tests {
i, tt := i, tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if i == len(tests)-1 {
require.Panics(t, func() { dec(kvPairs.Pairs[i], kvPairs.Pairs[i]) }, tt.name)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
// TestRandomizedGenState tests the normal scenario of applying RandomizedGenState.
// Abonormal scenarios are not tested here.
func TestRandomizedGenState(t *testing.T) {
t.Parallel()
interfaceRegistry := codectypes.NewInterfaceRegistry()
cryptocodec.RegisterInterfaces(interfaceRegistry)
cdc := codec.NewProtoCodec(interfaceRegistry)
Expand Down
1 change: 1 addition & 0 deletions modules/apps/27-interchain-accounts/types/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func (suite *TypesTestSuite) SetupTest() {
}

func TestTypesTestSuite(t *testing.T) {
t.Parallel()
suite.Run(t, new(TypesTestSuite))
}

Expand Down
1 change: 1 addition & 0 deletions modules/apps/29-fee/fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func (suite *FeeTestSuite) SetupTest() {
}

func TestIBCFeeTestSuite(t *testing.T) {
t.Parallel()
suite.Run(t, new(FeeTestSuite))
}

Expand Down
1 change: 1 addition & 0 deletions modules/apps/29-fee/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func (suite *KeeperTestSuite) SetupTest() {
}

func TestKeeperTestSuite(t *testing.T) {
t.Parallel()
suite.Run(t, new(KeeperTestSuite))
}

Expand Down
2 changes: 2 additions & 0 deletions modules/apps/29-fee/types/fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ var (
const invalidAddress = "invalid-address"

func TestFeeTotal(t *testing.T) {
t.Parallel()
fee := types.NewFee(defaultRecvFee, defaultAckFee, defaultTimeoutFee)

total := fee.Total()
require.Equal(t, sdk.NewInt(600), total.AmountOf(sdk.DefaultBondDenom))
}

func TestPacketFeeValidation(t *testing.T) {
t.Parallel()
var packetFee types.PacketFee

testCases := []struct {
Expand Down
2 changes: 2 additions & 0 deletions modules/apps/29-fee/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import (
)

func TestValidateDefaultGenesis(t *testing.T) {
t.Parallel()
err := types.DefaultGenesisState().Validate()
require.NoError(t, err)
}

func TestValidateGenesis(t *testing.T) {
t.Parallel()
var genState *types.GenesisState

testCases := []struct {
Expand Down
8 changes: 8 additions & 0 deletions modules/apps/29-fee/types/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import (
var validPacketID = channeltypes.NewPacketID(ibctesting.MockFeePort, ibctesting.FirstChannelID, 1)

func TestKeyPayee(t *testing.T) {
t.Parallel()
key := types.KeyPayee("relayer-address", ibctesting.FirstChannelID)
require.Equal(t, string(key), fmt.Sprintf("%s/%s/%s", types.PayeeKeyPrefix, "relayer-address", ibctesting.FirstChannelID))
}

func TestParseKeyPayee(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
key string
Expand Down Expand Up @@ -50,6 +52,7 @@ func TestParseKeyPayee(t *testing.T) {
}

func TestKeyCounterpartyPayee(t *testing.T) {
t.Parallel()
var (
relayerAddress = "relayer_address"
channelID = "channel-0"
Expand All @@ -60,11 +63,13 @@ func TestKeyCounterpartyPayee(t *testing.T) {
}

func TestKeyFeesInEscrow(t *testing.T) {
t.Parallel()
key := types.KeyFeesInEscrow(validPacketID)
require.Equal(t, string(key), fmt.Sprintf("%s/%s/%s/%d", types.FeesInEscrowPrefix, ibctesting.MockFeePort, ibctesting.FirstChannelID, 1))
}

func TestParseKeyFeeEnabled(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
key string
Expand Down Expand Up @@ -103,6 +108,7 @@ func TestParseKeyFeeEnabled(t *testing.T) {
}

func TestParseKeyFeesInEscrow(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
key string
Expand Down Expand Up @@ -138,6 +144,7 @@ func TestParseKeyFeesInEscrow(t *testing.T) {
}

func TestParseKeyForwardRelayerAddress(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
key string
Expand Down Expand Up @@ -173,6 +180,7 @@ func TestParseKeyForwardRelayerAddress(t *testing.T) {
}

func TestParseKeyCounterpartyPayee(t *testing.T) {
t.Parallel()
relayerAddress := "relayer_address"

testCases := []struct {
Expand Down
Loading

0 comments on commit 69933c3

Please sign in to comment.