aboutsummaryrefslogtreecommitdiffstats
path: root/whisper
diff options
context:
space:
mode:
authorb00ris <b00ris@mail.ru>2018-02-28 14:50:36 +0800
committerb00ris <b00ris@mail.ru>2018-02-28 14:50:36 +0800
commitcf52d5c91f4f9c583eecca63bce52c7df6dd2169 (patch)
tree751a3cb83cc79a8eca3ea504d49306268545045a /whisper
parentb574b5776695eb30e034fd8c7a468b3f03d4c6b9 (diff)
downloadgo-tangerine-cf52d5c91f4f9c583eecca63bce52c7df6dd2169.tar
go-tangerine-cf52d5c91f4f9c583eecca63bce52c7df6dd2169.tar.gz
go-tangerine-cf52d5c91f4f9c583eecca63bce52c7df6dd2169.tar.bz2
go-tangerine-cf52d5c91f4f9c583eecca63bce52c7df6dd2169.tar.lz
go-tangerine-cf52d5c91f4f9c583eecca63bce52c7df6dd2169.tar.xz
go-tangerine-cf52d5c91f4f9c583eecca63bce52c7df6dd2169.tar.zst
go-tangerine-cf52d5c91f4f9c583eecca63bce52c7df6dd2169.zip
whisper: fixed datarace
Diffstat (limited to 'whisper')
-rw-r--r--whisper/whisperv6/peer_test.go18
1 files changed, 11 insertions, 7 deletions
diff --git a/whisper/whisperv6/peer_test.go b/whisper/whisperv6/peer_test.go
index 9ce5eed8b..3d3dbd88a 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
}
@@ -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()
+ eqals := bytes.Equal(peer.bloomFilter, masterBloomFilter)
+ peer.bloomMu.Unlock()
+ if !eqals {
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)
}