Skip to content

Commit

Permalink
miner: run tests in parallel (ethereum#28506)
Browse files Browse the repository at this point in the history
Changes many of the tests in the miner package to run in parallel
  • Loading branch information
estensen authored Nov 15, 2023
1 parent 2814ee0 commit b9504e4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions miner/miner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -161,6 +163,7 @@ func TestMinerDownloaderFirstFails(t *testing.T) {
}

func TestMinerStartStopAfterDownloaderEvents(t *testing.T) {
t.Parallel()
miner, mux, cleanup := createMiner(t)
defer cleanup(false)

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions miner/ordering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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++ {
Expand Down
2 changes: 2 additions & 0 deletions miner/payload_building_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
)

func TestBuildPayload(t *testing.T) {
t.Parallel()
var (
db = rawdb.NewMemoryDatabase()
recipient = common.HexToAddress("0xdeadbeef")
Expand Down Expand Up @@ -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{
{
Expand Down
8 changes: 8 additions & 0 deletions miner/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()))
}

Expand Down Expand Up @@ -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()))
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b9504e4

Please sign in to comment.