From b9504e4966fa1e9451667c68426ab6e2a8e2dce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Anda=20Estensen?= Date: Wed, 15 Nov 2023 15:46:32 +0300 Subject: [PATCH] miner: run tests in parallel (#28506) Changes many of the tests in the miner package to run in parallel --- miner/miner_test.go | 7 +++++++ miner/ordering_test.go | 3 +++ miner/payload_building_test.go | 2 ++ miner/worker_test.go | 8 ++++++++ 4 files changed, 20 insertions(+) diff --git a/miner/miner_test.go b/miner/miner_test.go index 36d5166c6..411d6026c 100644 --- a/miner/miner_test.go +++ b/miner/miner_test.go @@ -99,6 +99,7 @@ func (bc *testBlockChain) SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) } func TestMiner(t *testing.T) { + t.Parallel() miner, mux, cleanup := createMiner(t) defer cleanup(false) @@ -128,6 +129,7 @@ func TestMiner(t *testing.T) { // An initial FailedEvent should allow mining to stop on a subsequent // downloader StartEvent. func TestMinerDownloaderFirstFails(t *testing.T) { + t.Parallel() miner, mux, cleanup := createMiner(t) defer cleanup(false) @@ -161,6 +163,7 @@ func TestMinerDownloaderFirstFails(t *testing.T) { } func TestMinerStartStopAfterDownloaderEvents(t *testing.T) { + t.Parallel() miner, mux, cleanup := createMiner(t) defer cleanup(false) @@ -185,6 +188,7 @@ func TestMinerStartStopAfterDownloaderEvents(t *testing.T) { } func TestStartWhileDownload(t *testing.T) { + t.Parallel() miner, mux, cleanup := createMiner(t) defer cleanup(false) waitForMiningState(t, miner, false) @@ -199,6 +203,7 @@ func TestStartWhileDownload(t *testing.T) { } func TestStartStopMiner(t *testing.T) { + t.Parallel() miner, _, cleanup := createMiner(t) defer cleanup(false) waitForMiningState(t, miner, false) @@ -209,6 +214,7 @@ func TestStartStopMiner(t *testing.T) { } func TestCloseMiner(t *testing.T) { + t.Parallel() miner, _, cleanup := createMiner(t) defer cleanup(true) waitForMiningState(t, miner, false) @@ -222,6 +228,7 @@ func TestCloseMiner(t *testing.T) { // TestMinerSetEtherbase checks that etherbase becomes set even if mining isn't // possible at the moment func TestMinerSetEtherbase(t *testing.T) { + t.Parallel() miner, mux, cleanup := createMiner(t) defer cleanup(false) miner.Start() diff --git a/miner/ordering_test.go b/miner/ordering_test.go index 59d478274..e5868d7a0 100644 --- a/miner/ordering_test.go +++ b/miner/ordering_test.go @@ -30,10 +30,12 @@ import ( ) func TestTransactionPriceNonceSortLegacy(t *testing.T) { + t.Parallel() testTransactionPriceNonceSort(t, nil) } func TestTransactionPriceNonceSort1559(t *testing.T) { + t.Parallel() testTransactionPriceNonceSort(t, big.NewInt(0)) testTransactionPriceNonceSort(t, big.NewInt(5)) testTransactionPriceNonceSort(t, big.NewInt(50)) @@ -138,6 +140,7 @@ func testTransactionPriceNonceSort(t *testing.T, baseFee *big.Int) { // Tests that if multiple transactions have the same price, the ones seen earlier // are prioritized to avoid network spam attacks aiming for a specific ordering. func TestTransactionTimeSort(t *testing.T) { + t.Parallel() // Generate a batch of accounts to start with keys := make([]*ecdsa.PrivateKey, 5) for i := 0; i < len(keys); i++ { diff --git a/miner/payload_building_test.go b/miner/payload_building_test.go index 6f5736344..928363522 100644 --- a/miner/payload_building_test.go +++ b/miner/payload_building_test.go @@ -30,6 +30,7 @@ import ( ) func TestBuildPayload(t *testing.T) { + t.Parallel() var ( db = rawdb.NewMemoryDatabase() recipient = common.HexToAddress("0xdeadbeef") @@ -82,6 +83,7 @@ func TestBuildPayload(t *testing.T) { } func TestPayloadId(t *testing.T) { + t.Parallel() ids := make(map[string]int) for i, tt := range []*BuildPayloadArgs{ { diff --git a/miner/worker_test.go b/miner/worker_test.go index 9c4694c0e..59fbbbcdc 100644 --- a/miner/worker_test.go +++ b/miner/worker_test.go @@ -167,6 +167,7 @@ func newTestWorker(t *testing.T, chainConfig *params.ChainConfig, engine consens } func TestGenerateAndImportBlock(t *testing.T) { + t.Parallel() var ( db = rawdb.NewMemoryDatabase() config = *params.AllCliqueProtocolChanges @@ -210,9 +211,11 @@ func TestGenerateAndImportBlock(t *testing.T) { } func TestEmptyWorkEthash(t *testing.T) { + t.Parallel() testEmptyWork(t, ethashChainConfig, ethash.NewFaker()) } func TestEmptyWorkClique(t *testing.T) { + t.Parallel() testEmptyWork(t, cliqueChainConfig, clique.New(cliqueChainConfig.Clique, rawdb.NewMemoryDatabase())) } @@ -252,10 +255,12 @@ func testEmptyWork(t *testing.T, chainConfig *params.ChainConfig, engine consens } func TestAdjustIntervalEthash(t *testing.T) { + t.Parallel() testAdjustInterval(t, ethashChainConfig, ethash.NewFaker()) } func TestAdjustIntervalClique(t *testing.T) { + t.Parallel() testAdjustInterval(t, cliqueChainConfig, clique.New(cliqueChainConfig.Clique, rawdb.NewMemoryDatabase())) } @@ -346,14 +351,17 @@ func testAdjustInterval(t *testing.T, chainConfig *params.ChainConfig, engine co } func TestGetSealingWorkEthash(t *testing.T) { + t.Parallel() testGetSealingWork(t, ethashChainConfig, ethash.NewFaker()) } func TestGetSealingWorkClique(t *testing.T) { + t.Parallel() testGetSealingWork(t, cliqueChainConfig, clique.New(cliqueChainConfig.Clique, rawdb.NewMemoryDatabase())) } func TestGetSealingWorkPostMerge(t *testing.T) { + t.Parallel() local := new(params.ChainConfig) *local = *ethashChainConfig local.TerminalTotalDifficulty = big.NewInt(0)