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(ci): Speed up CI, Add t.Parallel and Fix Test Parallelism Issue #2459

Merged
merged 5 commits into from
Feb 1, 2025
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
13 changes: 11 additions & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ linters-settings:
# Default: false
check-type-assertions: true

paralleltest:
# Ignore missing calls to `t.Parallel()` and only report incorrect uses of it.
# Default: false
ignore-missing: false
# Ignore missing calls to `t.Parallel()` in subtests. Top-level tests are
# still required to have `t.Parallel`, but subtests are allowed to skip it.
# Default: false
ignore-missing-subtests: true

exhaustive:
# Program elements to check for exhaustiveness.
# Default: [ switch ]
Expand Down Expand Up @@ -292,7 +301,7 @@ linters:
- testableexamples # checks if examples are testable (have an expected output)
- testifylint # checks usage of github.com/stretchr/testify
- testpackage # makes you use a separate _test package
- tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes
# - tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes. Replaced with paralleltest
- unconvert # removes unnecessary type conversions
- unparam # reports unused function parameters
- usestdlibvars # detects the possibility to use variables/constants from the Go standard library
Expand Down Expand Up @@ -333,7 +342,7 @@ linters:
- maintidx # measures the maintainability index of each function
- misspell # [useless] finds commonly misspelled English words in comments
#- nlreturn # [too strict and mostly code is not more readable] checks for a new line before return and branch statements to increase code clarity
#- paralleltest # [too many false positives] detects missing usage of t.Parallel() method in your Go test
- paralleltest # detects missing usage of t.Parallel() method in your Go test
# - tagliatelle # checks the struct tags
- thelper # detects golang test helpers without t.Helper() call and checks the consistency of test helpers
#- wsl # [too strict and mostly code is not more readable] whitespace linter forces you to use empty lines
Expand Down
2 changes: 2 additions & 0 deletions beacon/payload-time/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
// TestNextTimestampVerifies checks that next payload timestamp
// built via payloadtime.Next always pass payloadtime.Verify.
func TestNextTimestampVerifies(t *testing.T) {
t.Parallel()
tests := []struct {
name string
times func() (time.Time, time.Time)
Expand Down Expand Up @@ -68,6 +69,7 @@ func TestNextTimestampVerifies(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
consensusTime, parentPayloadTimestamp := tt.times()

// Optimistic build case
Expand Down
8 changes: 8 additions & 0 deletions chain/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var spec, _ = chain.NewSpec(

// TestActiveForkVersionForEpoch tests the ActiveForkVersionForEpoch method.
func TestActiveForkVersionForEpoch(t *testing.T) {
t.Parallel()
// Define test cases
tests := []struct {
name string
Expand All @@ -59,6 +60,7 @@ func TestActiveForkVersionForEpoch(t *testing.T) {
// Run test cases
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
result := spec.ActiveForkVersionForEpoch(tt.epoch)
require.Equal(t, tt.expected, result, "Test case : %s", tt.name)
})
Expand All @@ -67,6 +69,7 @@ func TestActiveForkVersionForEpoch(t *testing.T) {

// TestSlotToEpoch tests the SlotToEpoch method.
func TestSlotToEpoch(t *testing.T) {
t.Parallel()
// Define test cases
tests := []struct {
name string
Expand All @@ -84,6 +87,7 @@ func TestSlotToEpoch(t *testing.T) {
// Run test cases
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
result := spec.SlotToEpoch(tt.slot)
require.Equal(t, tt.expected, result, "Test case : %s", tt.name)
})
Expand All @@ -92,6 +96,7 @@ func TestSlotToEpoch(t *testing.T) {

// TestActiveForkVersionForSlot tests the ActiveForkVersionForSlot method.
func TestActiveForkVersionForSlot(t *testing.T) {
t.Parallel()
// Define test cases
tests := []struct {
name string
Expand All @@ -111,6 +116,7 @@ func TestActiveForkVersionForSlot(t *testing.T) {
// Run test cases
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
result := spec.ActiveForkVersionForSlot(tt.slot)
require.Equal(t, tt.expected, result, "Test case : %s", tt.name)
})
Expand All @@ -119,6 +125,7 @@ func TestActiveForkVersionForSlot(t *testing.T) {

// TestWithinDAPeriod tests the WithinDAPeriod method.
func TestWithinDAPeriod(t *testing.T) {
t.Parallel()
// Define test cases
tests := []struct {
name string
Expand All @@ -144,6 +151,7 @@ func TestWithinDAPeriod(t *testing.T) {
// Run test cases
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
result := spec.WithinDAPeriod(tt.block, tt.current)
require.Equal(t, tt.expected, result, "Test case : %s", tt.name)
})
Expand Down
2 changes: 2 additions & 0 deletions cli/commands/deposit/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import (
)

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

qc := &quick.Config{MaxCount: 100}

cs, err := spec.DevnetChainSpec()
Expand Down
1 change: 1 addition & 0 deletions cli/commands/genesis/deposit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
)

func TestGenesisDeposit(t *testing.T) {
t.Parallel()
homeDir := t.TempDir()
t.Log("Home folder:", homeDir)

Expand Down
7 changes: 4 additions & 3 deletions cli/commands/genesis/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,19 @@ import (
)

func TestSetDepositStorageCmd(t *testing.T) {
t.Parallel()
t.Run("command should be available and have correct use", func(t *testing.T) {
t.Parallel()
chainSpec, err := spec.DevnetChainSpec()
require.NoError(t, err)
cmd := genesis.SetDepositStorageCmd(chainSpec)
require.Equal(t, "set-deposit-storage [eth/genesis/file.json]", cmd.Use)
})

t.Run("should set deposit storage correctly", func(t *testing.T) {
t.Parallel()
// Create a temporary directory for test files
tmpDir, err := os.MkdirTemp("", "genesis-test-*")
require.NoError(t, err)
defer os.RemoveAll(tmpDir)
tmpDir := t.TempDir()

// Setup test files
mockGenesisPath := setupMockGenesis(t, tmpDir)
Expand Down
1 change: 1 addition & 0 deletions cli/commands/jwt/jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
)

func Test_NewGenerateJWTCommand(t *testing.T) {
t.Parallel()
t.Run(
"command should be available and have correct use",
func(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions config/spec/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
)

func TestDomainTypeConversion(t *testing.T) {
t.Parallel()
cs := spec.MainnetChainSpecData()
require.Equal(t, bytes.B4([]byte{0x00, 0x00, 0x00, 0x00}), cs.DomainTypeProposer)
require.Equal(t, bytes.B4([]byte{0x01, 0x00, 0x00, 0x00}), cs.DomainTypeAttester)
Expand Down
4 changes: 4 additions & 0 deletions consensus-types/types/attestation_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func generateAttestationData() *types.AttestationData {
}

func TestAttestationData_MarshalSSZ_UnmarshalSSZ(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
data *types.AttestationData
Expand Down Expand Up @@ -78,6 +79,7 @@ func TestAttestationData_MarshalSSZ_UnmarshalSSZ(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
data, err := tc.data.MarshalSSZ()
require.NoError(t, err)
require.NotNil(t, data)
Expand All @@ -104,6 +106,7 @@ func TestAttestationData_MarshalSSZ_UnmarshalSSZ(t *testing.T) {
}

func TestAttestationData_GetTree(t *testing.T) {
t.Parallel()
data := generateAttestationData()

tree, err := data.GetTree()
Expand All @@ -118,6 +121,7 @@ func TestAttestationData_GetTree(t *testing.T) {
}

func TestAttestationData_Getters(t *testing.T) {
t.Parallel()
data := generateAttestationData()
beaconBlockRoot := common.Root{
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
Expand Down
7 changes: 7 additions & 0 deletions consensus-types/types/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func generateValidBeaconBlock(t *testing.T) *types.BeaconBlock {
}

func TestBeaconBlockForDeneb(t *testing.T) {
t.Parallel()
deneb1 := version.Deneb1()
block, err := types.NewBeaconBlockWithVersion(
math.Slot(10),
Expand All @@ -98,6 +99,7 @@ func TestBeaconBlockForDeneb(t *testing.T) {
}

func TestBeaconBlock(t *testing.T) {
t.Parallel()
block := generateValidBeaconBlock(t)

require.NotNil(t, block.Body)
Expand All @@ -121,6 +123,7 @@ func TestBeaconBlock(t *testing.T) {
}

func TestBeaconBlock_MarshalUnmarshalSSZ(t *testing.T) {
t.Parallel()
block := *generateValidBeaconBlock(t)

sszBlock, err := block.MarshalSSZ()
Expand All @@ -137,17 +140,20 @@ func TestBeaconBlock_MarshalUnmarshalSSZ(t *testing.T) {
}

func TestBeaconBlock_HashTreeRoot(t *testing.T) {
t.Parallel()
block := generateValidBeaconBlock(t)
hashRoot := block.HashTreeRoot()
require.NotNil(t, hashRoot)
}

func TestBeaconBlock_IsNil(t *testing.T) {
t.Parallel()
var block *types.BeaconBlock
require.True(t, block.IsNil())
}

func TestNewWithVersion(t *testing.T) {
t.Parallel()
slot := math.Slot(10)
proposerIndex := math.ValidatorIndex(5)
parentBlockRoot := common.Root{1, 2, 3, 4, 5}
Expand All @@ -168,6 +174,7 @@ func TestNewWithVersion(t *testing.T) {
}

func TestNewWithVersionInvalidForkVersion(t *testing.T) {
t.Parallel()
slot := math.Slot(10)
proposerIndex := math.ValidatorIndex(5)
parentBlockRoot := common.Root{1, 2, 3, 4, 5}
Expand Down
16 changes: 16 additions & 0 deletions consensus-types/types/body_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func generateBeaconBlockBody() types.BeaconBlockBody {
}

func TestBeaconBlockBodyBase(t *testing.T) {
t.Parallel()
body := types.BeaconBlockBody{
RandaoReveal: [96]byte{1, 2, 3},
Eth1Data: &types.Eth1Data{},
Expand All @@ -76,6 +77,7 @@ func TestBeaconBlockBodyBase(t *testing.T) {
}

func TestBeaconBlockBody(t *testing.T) {
t.Parallel()
body := types.BeaconBlockBody{
RandaoReveal: [96]byte{1, 2, 3},
Eth1Data: &types.Eth1Data{},
Expand All @@ -92,6 +94,7 @@ func TestBeaconBlockBody(t *testing.T) {
}

func TestBeaconBlockBody_SetBlobKzgCommitments(t *testing.T) {
t.Parallel()
body := types.BeaconBlockBody{}
commitments := eip4844.KZGCommitments[common.ExecutionHash]{}
body.SetBlobKzgCommitments(commitments)
Expand All @@ -100,6 +103,7 @@ func TestBeaconBlockBody_SetBlobKzgCommitments(t *testing.T) {
}

func TestBeaconBlockBody_SetRandaoReveal(t *testing.T) {
t.Parallel()
body := types.BeaconBlockBody{}
randaoReveal := crypto.BLSSignature{1, 2, 3}
body.SetRandaoReveal(randaoReveal)
Expand All @@ -108,6 +112,7 @@ func TestBeaconBlockBody_SetRandaoReveal(t *testing.T) {
}

func TestBeaconBlockBody_SetEth1Data(t *testing.T) {
t.Parallel()
body := types.BeaconBlockBody{}
eth1Data := &types.Eth1Data{}
body.SetEth1Data(eth1Data)
Expand All @@ -116,6 +121,7 @@ func TestBeaconBlockBody_SetEth1Data(t *testing.T) {
}

func TestBeaconBlockBody_SetDeposits(t *testing.T) {
t.Parallel()
body := types.BeaconBlockBody{}
deposits := types.Deposits{}
body.SetDeposits(deposits)
Expand All @@ -124,6 +130,7 @@ func TestBeaconBlockBody_SetDeposits(t *testing.T) {
}

func TestBeaconBlockBody_MarshalSSZ(t *testing.T) {
t.Parallel()
body := types.BeaconBlockBody{
RandaoReveal: [96]byte{1, 2, 3},
Eth1Data: &types.Eth1Data{},
Expand All @@ -139,19 +146,22 @@ func TestBeaconBlockBody_MarshalSSZ(t *testing.T) {
}

func TestBeaconBlockBody_GetTopLevelRoots(t *testing.T) {
t.Parallel()
body := generateBeaconBlockBody()
roots := body.GetTopLevelRoots()
require.NotNil(t, roots)
}

func TestBeaconBlockBody_Empty(t *testing.T) {
t.Parallel()
body := types.BeaconBlockBody{}
require.NotNil(t, body)
}

// Ensure that the ProposerSlashings field cannot be unmarshaled with data in it,
// enforcing that it's unused.
func TestBeaconBlockBody_UnusedProposerSlashingsEnforcement(t *testing.T) {
t.Parallel()
blockBody := types.BeaconBlockBody{}
unused := types.UnusedType(1)
blockBody.SetProposerSlashings(types.ProposerSlashings{&unused})
Expand All @@ -170,6 +180,7 @@ func TestBeaconBlockBody_UnusedProposerSlashingsEnforcement(t *testing.T) {
// Ensure that the AttesterSlashings field cannot be unmarshaled with data in it,
// enforcing that it's unused.
func TestBeaconBlockBody_UnusedAttesterSlashingsEnforcement(t *testing.T) {
t.Parallel()
blockBody := types.BeaconBlockBody{}
unused := types.UnusedType(1)
blockBody.SetAttesterSlashings(types.AttesterSlashings{&unused})
Expand All @@ -188,6 +199,7 @@ func TestBeaconBlockBody_UnusedAttesterSlashingsEnforcement(t *testing.T) {
// Ensure that the Attestations field cannot be unmarshaled with data in it,
// enforcing that it's unused.
func TestBeaconBlockBody_UnusedAttestationsEnforcement(t *testing.T) {
t.Parallel()
blockBody := types.BeaconBlockBody{}
unused := types.UnusedType(1)
blockBody.SetAttestations(types.Attestations{&unused})
Expand All @@ -206,6 +218,7 @@ func TestBeaconBlockBody_UnusedAttestationsEnforcement(t *testing.T) {
// Ensure that the VoluntaryExits field cannot be unmarshaled with data in it,
// enforcing that it's unused.
func TestBeaconBlockBody_UnusedVoluntaryExitsEnforcement(t *testing.T) {
t.Parallel()
blockBody := types.BeaconBlockBody{}
unused := types.UnusedType(1)
blockBody.SetVoluntaryExits(types.VoluntaryExits{&unused})
Expand All @@ -224,6 +237,7 @@ func TestBeaconBlockBody_UnusedVoluntaryExitsEnforcement(t *testing.T) {
// Ensure that the BlsToExecutionChanges field cannot be unmarshaled with data in it,
// enforcing that it's unused.
func TestBeaconBlockBody_UnusedBlsToExecutionChangesEnforcement(t *testing.T) {
t.Parallel()
blockBody := types.BeaconBlockBody{}
unused := types.UnusedType(1)
blockBody.SetBlsToExecutionChanges(types.BlsToExecutionChanges{&unused})
Expand All @@ -240,6 +254,7 @@ func TestBeaconBlockBody_UnusedBlsToExecutionChangesEnforcement(t *testing.T) {
}

func TestBeaconBlockBody_RoundTrip_HashTreeRoot(t *testing.T) {
t.Parallel()
body := generateBeaconBlockBody()
data, err := body.MarshalSSZ()
require.NoError(t, err)
Expand All @@ -253,6 +268,7 @@ func TestBeaconBlockBody_RoundTrip_HashTreeRoot(t *testing.T) {

// This test explains the calculation of the KZG commitment' inclusion proof depth.
func Test_KZGCommitmentInclusionProofDepth(t *testing.T) {
t.Parallel()
maxUint8 := uint64(^uint8(0))
cs, err := spec.DevnetChainSpec()
require.NoError(t, err)
Expand Down
Loading
Loading