les, miner, accounts/abi/bind: fix load-sensitive unit tests (#20698)

This commit is contained in:
gary rong
2020-02-20 20:05:54 +08:00
committed by GitHub
parent 6df973df27
commit 2e1ecc02bd
3 changed files with 13 additions and 7 deletions

View File

@ -215,12 +215,16 @@ func testGenerateBlockAndImport(t *testing.T, isClique bool) {
chain, _ := core.NewBlockChain(db2, nil, b.chain.Config(), engine, vm.Config{}, nil)
defer chain.Stop()
loopErr := make(chan error)
newBlock := make(chan struct{})
var (
loopErr = make(chan error)
newBlock = make(chan struct{})
subscribe = make(chan struct{})
)
listenNewBlock := func() {
sub := w.mux.Subscribe(core.NewMinedBlockEvent{})
defer sub.Unsubscribe()
subscribe <- struct{}{}
for item := range sub.Chan() {
block := item.Data.(core.NewMinedBlockEvent).Block
_, err := chain.InsertChain([]*types.Block{block})
@ -234,9 +238,11 @@ func testGenerateBlockAndImport(t *testing.T, isClique bool) {
w.skipSealHook = func(task *task) bool {
return len(task.receipts) == 0
}
w.start() // Start mining!
go listenNewBlock()
<-subscribe // Ensure the subscription is created
w.start() // Start mining!
for i := 0; i < 5; i++ {
b.txPool.AddLocal(b.newRandomTx(true))
b.txPool.AddLocal(b.newRandomTx(false))