From 4c4f21293ef5243267c9fac7deab0b0dc7630141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Anda=20Estensen?= Date: Mon, 16 Sep 2024 08:44:47 +0200 Subject: [PATCH] internal: run tests in parallel (#30381) Continuation of https://github.com/ethereum/go-ethereum/pull/28546 --- internal/era/e2store/e2store_test.go | 5 +++++ internal/era/era_test.go | 4 ++++ internal/ethapi/api_test.go | 7 ++++++- internal/ethapi/transaction_args_test.go | 2 ++ internal/flags/flags_test.go | 14 ++++++++++---- internal/guide/guide_test.go | 2 ++ internal/jsre/completion_test.go | 14 ++++++++++---- internal/jsre/jsre_test.go | 8 ++++++++ internal/utesting/utesting_test.go | 6 ++++++ 9 files changed, 53 insertions(+), 9 deletions(-) diff --git a/internal/era/e2store/e2store_test.go b/internal/era/e2store/e2store_test.go index b0803493c7..353942f0bd 100644 --- a/internal/era/e2store/e2store_test.go +++ b/internal/era/e2store/e2store_test.go @@ -26,6 +26,8 @@ import ( ) func TestEncode(t *testing.T) { + t.Parallel() + for _, test := range []struct { entries []Entry want string @@ -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) @@ -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 diff --git a/internal/era/era_test.go b/internal/era/era_test.go index 883e30f7b6..d0f56b6f88 100644 --- a/internal/era/era_test.go +++ b/internal/era/era_test.go @@ -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 { @@ -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 diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index f2dd93e4ac..384ca9f1cc 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -61,7 +61,6 @@ import ( ) func testTransactionMarshal(t *testing.T, tests []txData, config *params.ChainConfig) { - t.Parallel() var ( signer = types.LatestSigner(config) key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") @@ -98,6 +97,8 @@ func testTransactionMarshal(t *testing.T, tests []txData, config *params.ChainCo } func TestTransaction_RoundTripRpcJSON(t *testing.T) { + t.Parallel() + var ( config = params.AllEthashProtocolChanges tests = allTransactionTypes(common.Address{0xde, 0xad}, config) @@ -106,6 +107,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) @@ -2460,6 +2463,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 { diff --git a/internal/ethapi/transaction_args_test.go b/internal/ethapi/transaction_args_test.go index 6750fc07a9..5317828173 100644 --- a/internal/ethapi/transaction_args_test.go +++ b/internal/ethapi/transaction_args_test.go @@ -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 diff --git a/internal/flags/flags_test.go b/internal/flags/flags_test.go index 681586b46c..cfe16b340e 100644 --- a/internal/flags/flags_test.go +++ b/internal/flags/flags_test.go @@ -24,6 +24,8 @@ import ( ) func TestPathExpansion(t *testing.T) { + t.Parallel() + user, _ := user.Current() var tests map[string]string @@ -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) + } + }) } } diff --git a/internal/guide/guide_test.go b/internal/guide/guide_test.go index f682daac91..573898d7d0 100644 --- a/internal/guide/guide_test.go +++ b/internal/guide/guide_test.go @@ -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() diff --git a/internal/jsre/completion_test.go b/internal/jsre/completion_test.go index 953bc5026d..8fbddbc299 100644 --- a/internal/jsre/completion_test.go +++ b/internal/jsre/completion_test.go @@ -23,6 +23,8 @@ import ( ) func TestCompleteKeywords(t *testing.T) { + t.Parallel() + re := New("", os.Stdout) re.Run(` function theClass() { @@ -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) + } + }) } } diff --git a/internal/jsre/jsre_test.go b/internal/jsre/jsre_test.go index 18ef39e2f4..a812d6116d 100644 --- a/internal/jsre/jsre_test.go +++ b/internal/jsre/jsre_test.go @@ -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") @@ -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") @@ -96,6 +100,8 @@ func TestNatto(t *testing.T) { } func TestBind(t *testing.T) { + t.Parallel() + jsre := New("", os.Stdout) defer jsre.Stop(false) @@ -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")`) diff --git a/internal/utesting/utesting_test.go b/internal/utesting/utesting_test.go index 31c7911c52..526d36bab1 100644 --- a/internal/utesting/utesting_test.go +++ b/internal/utesting/utesting_test.go @@ -24,6 +24,8 @@ import ( ) func TestTest(t *testing.T) { + t.Parallel() + tests := []Test{ { Name: "successful test", @@ -90,6 +92,8 @@ var outputTests = []Test{ } func TestOutput(t *testing.T) { + t.Parallel() + var buf bytes.Buffer RunTests(outputTests, &buf) @@ -116,6 +120,8 @@ $`[1:]) } func TestOutputTAP(t *testing.T) { + t.Parallel() + var buf bytes.Buffer RunTAP(outputTests, &buf)