Skip to content

Commit

Permalink
fix race in testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
auxten committed May 4, 2018
1 parent 8b52715 commit 0179a73
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pow/cpuminer/miner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (

"time"

"sync"

"github.com/thunderdb/ThunderDB/crypto/hash"
)

Expand All @@ -52,10 +54,14 @@ func TestCPUMiner_HashBlock(t *testing.T) {
var (
err error
)
var wg sync.WaitGroup
wg.Add(1)
go func() {
err = miner.CalculateBlockNonce(block, *big.NewInt(0), diffWanted)
wg.Done()
}()
nonceFromCh := <-nonceCh
wg.Wait()

hash := hash.DoubleHashH(append(data, nonceFromCh.Nonce.Bytes()...))
if err != nil || nonceFromCh.Difficulty < diffWanted || hash.Difficulty() < diffWanted {
Expand Down

0 comments on commit 0179a73

Please sign in to comment.