From 8f1377585c53c6c1a2b529c26126b530416f4767 Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Thu, 20 Feb 2020 14:52:55 +0800 Subject: [PATCH] miner: fix miner test --- miner/worker_test.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/miner/worker_test.go b/miner/worker_test.go index 81fb8f1b94..78e09a1767 100644 --- a/miner/worker_test.go +++ b/miner/worker_test.go @@ -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))