diff options
author | Javier Peletier <jm@epiclabs.io> | 2018-03-05 23:00:03 +0800 |
---|---|---|
committer | Javier Peletier <jm@epiclabs.io> | 2018-03-05 23:00:03 +0800 |
commit | 13b566e06e9aae28bddde431c7d53a335272411a (patch) | |
tree | b649ab64ca2c00327500aed5c826d5a6f454a6cf /whisper/whisperv6/peer_test.go | |
parent | 1e72271f571f916691c5c18b8f0c4c5f7e0445c3 (diff) | |
parent | 1548518644071c8fa8eb98a8cb8a8c4603400acb (diff) | |
download | go-tangerine-13b566e06e9aae28bddde431c7d53a335272411a.tar go-tangerine-13b566e06e9aae28bddde431c7d53a335272411a.tar.gz go-tangerine-13b566e06e9aae28bddde431c7d53a335272411a.tar.bz2 go-tangerine-13b566e06e9aae28bddde431c7d53a335272411a.tar.lz go-tangerine-13b566e06e9aae28bddde431c7d53a335272411a.tar.xz go-tangerine-13b566e06e9aae28bddde431c7d53a335272411a.tar.zst go-tangerine-13b566e06e9aae28bddde431c7d53a335272411a.zip |
accounts/abi: Add one-parameter event test case from enriquefynn/unpack_one_arg_event
Diffstat (limited to 'whisper/whisperv6/peer_test.go')
-rw-r--r-- | whisper/whisperv6/peer_test.go | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/whisper/whisperv6/peer_test.go b/whisper/whisperv6/peer_test.go index 9ce5eed8b..ec985ae65 100644 --- a/whisper/whisperv6/peer_test.go +++ b/whisper/whisperv6/peer_test.go @@ -23,6 +23,7 @@ import ( mrand "math/rand" "net" "sync" + "sync/atomic" "testing" "time" @@ -71,7 +72,7 @@ var keys = []string{ } type TestData struct { - started int + started int64 counter [NumNodes]int mutex sync.RWMutex } @@ -151,7 +152,7 @@ func resetParams(t *testing.T) { } func initBloom(t *testing.T) { - masterBloomFilter = make([]byte, bloomFilterSize) + masterBloomFilter = make([]byte, BloomFilterSize) _, err := mrand.Read(masterBloomFilter) if err != nil { t.Fatalf("rand failed: %s.", err) @@ -163,7 +164,7 @@ func initBloom(t *testing.T) { masterBloomFilter[i] = 0xFF } - if !bloomFilterMatch(masterBloomFilter, msgBloom) { + if !BloomFilterMatch(masterBloomFilter, msgBloom) { t.Fatalf("bloom mismatch on initBloom.") } } @@ -177,7 +178,7 @@ func initialize(t *testing.T) { for i := 0; i < NumNodes; i++ { var node TestNode - b := make([]byte, bloomFilterSize) + b := make([]byte, BloomFilterSize) copy(b, masterBloomFilter) node.shh = New(&DefaultConfig) node.shh.SetMinimumPoW(masterPow) @@ -240,9 +241,7 @@ func startServer(t *testing.T, s *p2p.Server) { t.Fatalf("failed to start the fisrt server.") } - result.mutex.Lock() - defer result.mutex.Unlock() - result.started++ + atomic.AddInt64(&result.started, 1) } func stopServers() { @@ -472,7 +471,10 @@ func checkPowExchange(t *testing.T) { func checkBloomFilterExchangeOnce(t *testing.T, mustPass bool) bool { for i, node := range nodes { for peer := range node.shh.peers { - if !bytes.Equal(peer.bloomFilter, masterBloomFilter) { + peer.bloomMu.Lock() + equals := bytes.Equal(peer.bloomFilter, masterBloomFilter) + peer.bloomMu.Unlock() + if !equals { if mustPass { t.Fatalf("node %d: failed to exchange bloom filter requirement in round %d. \n%x expected \n%x got", i, round, masterBloomFilter, peer.bloomFilter) @@ -500,11 +502,13 @@ func checkBloomFilterExchange(t *testing.T) { func waitForServersToStart(t *testing.T) { const iterations = 200 + var started int64 for j := 0; j < iterations; j++ { time.Sleep(50 * time.Millisecond) - if result.started == NumNodes { + started = atomic.LoadInt64(&result.started) + if started == NumNodes { return } } - t.Fatalf("Failed to start all the servers, running: %d", result.started) + t.Fatalf("Failed to start all the servers, running: %d", started) } |