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

internal: run tests in parallel #30381

Merged
merged 1 commit into from
Sep 16, 2024
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
5 changes: 5 additions & 0 deletions internal/era/e2store/e2store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
)

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

for _, test := range []struct {
entries []Entry
want string
Expand Down Expand Up @@ -53,6 +55,7 @@ func TestEncode(t *testing.T) {
tt := test
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

var (
b = bytes.NewBuffer(nil)
w = NewWriter(b)
Expand Down Expand Up @@ -83,6 +86,8 @@ func TestEncode(t *testing.T) {
}

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

for i, tt := range []struct {
have string
err error
Expand Down
4 changes: 4 additions & 0 deletions internal/era/era_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type testchain struct {
}

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

// Get temp directory.
f, err := os.CreateTemp("", "era1-test")
if err != nil {
Expand Down Expand Up @@ -125,6 +127,8 @@ func TestEra1Builder(t *testing.T) {
}

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

for i, tt := range []struct {
network string
epoch int
Expand Down
7 changes: 6 additions & 1 deletion internal/ethapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ import (
)

func testTransactionMarshal(t *testing.T, tests []txData, config *params.ChainConfig) {
t.Parallel()
var (
signer = types.LatestSigner(config)
key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
Expand Down Expand Up @@ -96,6 +95,8 @@ func testTransactionMarshal(t *testing.T, tests []txData, config *params.ChainCo
}

func TestTransaction_RoundTripRpcJSON(t *testing.T) {
t.Parallel()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is moving it to the outer better than the inner one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it’s easier to see that a test is running in parallel when t.Parallel() is placed at the outer level, as it clearly indicates the parallelism applies to the entire test case.


var (
config = params.AllEthashProtocolChanges
tests = allTransactionTypes(common.Address{0xde, 0xad}, config)
Expand All @@ -104,6 +105,8 @@ func TestTransaction_RoundTripRpcJSON(t *testing.T) {
}

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

config := *params.TestChainConfig
config.ShanghaiTime = new(uint64)
config.CancunTime = new(uint64)
Expand Down Expand Up @@ -1272,6 +1275,8 @@ func TestFillBlobTransaction(t *testing.T) {
}
for _, tc := range suite {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

res, err := api.FillTransaction(context.Background(), tc.args)
if len(tc.err) > 0 {
if err == nil {
Expand Down
2 changes: 2 additions & 0 deletions internal/ethapi/transaction_args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import (

// TestSetFeeDefaults tests the logic for filling in default fee values works as expected.
func TestSetFeeDefaults(t *testing.T) {
t.Parallel()

type test struct {
name string
fork string // options: legacy, london, cancun
Expand Down
14 changes: 10 additions & 4 deletions internal/flags/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
)

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

user, _ := user.Current()
var tests map[string]string

Expand Down Expand Up @@ -53,9 +55,13 @@ func TestPathExpansion(t *testing.T) {

os.Setenv(`DDDXXX`, `/tmp`)
for test, expected := range tests {
got := expandPath(test)
if got != expected {
t.Errorf(`test %s, got %s, expected %s\n`, test, got, expected)
}
t.Run(test, func(t *testing.T) {
t.Parallel()

got := expandPath(test)
if got != expected {
t.Errorf(`test %s, got %s, expected %s\n`, test, got, expected)
}
})
}
}
2 changes: 2 additions & 0 deletions internal/guide/guide_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import (

// Tests that the account management snippets work correctly.
func TestAccountManagement(t *testing.T) {
t.Parallel()

// Create a temporary folder to work with
workdir := t.TempDir()

Expand Down
14 changes: 10 additions & 4 deletions internal/jsre/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
)

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

re := New("", os.Stdout)
re.Run(`
function theClass() {
Expand Down Expand Up @@ -85,9 +87,13 @@ func TestCompleteKeywords(t *testing.T) {
},
}
for _, test := range tests {
cs := re.CompleteKeywords(test.input)
if !reflect.DeepEqual(cs, test.want) {
t.Errorf("wrong completions for %q\ngot %v\nwant %v", test.input, cs, test.want)
}
t.Run(test.input, func(t *testing.T) {
t.Parallel()

cs := re.CompleteKeywords(test.input)
if !reflect.DeepEqual(cs, test.want) {
t.Errorf("wrong completions for %q\ngot %v\nwant %v", test.input, cs, test.want)
}
})
}
}
8 changes: 8 additions & 0 deletions internal/jsre/jsre_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func newWithTestJS(t *testing.T, testjs string) *JSRE {
}

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

jsre := newWithTestJS(t, `msg = "testMsg"`)

err := jsre.Exec("test.js")
Expand All @@ -73,6 +75,8 @@ func TestExec(t *testing.T) {
}

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

jsre := newWithTestJS(t, `setTimeout(function(){msg = "testMsg"}, 1);`)

err := jsre.Exec("test.js")
Expand All @@ -96,6 +100,8 @@ func TestNatto(t *testing.T) {
}

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

jsre := New("", os.Stdout)
defer jsre.Stop(false)

Expand All @@ -108,6 +114,8 @@ func TestBind(t *testing.T) {
}

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

jsre := newWithTestJS(t, `msg = "testMsg"`)

_, err := jsre.Run(`loadScript("test.js")`)
Expand Down
6 changes: 6 additions & 0 deletions internal/utesting/utesting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
)

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

tests := []Test{
{
Name: "successful test",
Expand Down Expand Up @@ -90,6 +92,8 @@ var outputTests = []Test{
}

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

var buf bytes.Buffer
RunTests(outputTests, &buf)

Expand All @@ -116,6 +120,8 @@ $`[1:])
}

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

var buf bytes.Buffer
RunTAP(outputTests, &buf)

Expand Down