mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-20 21:54:30 +00:00
all: fix staticcheck warning SA2002: must call T.Fatalf in same goroutine
This commit is contained in:
parent
52dd69ecdb
commit
11285be830
3 changed files with 16 additions and 36 deletions
|
|
@ -986,14 +986,17 @@ func TestCanonicalBlockRetrieval(t *testing.T) {
|
|||
continue // busy wait for canonical hash to be written
|
||||
}
|
||||
if ch != block.Hash() {
|
||||
t.Fatalf("unknown canonical hash, want %s, got %s", block.Hash().Hex(), ch.Hex())
|
||||
t.Errorf("unknown canonical hash, want %s, got %s", block.Hash().Hex(), ch.Hex())
|
||||
return
|
||||
}
|
||||
fb := GetBlock(blockchain.db, ch, block.NumberU64())
|
||||
if fb == nil {
|
||||
t.Fatalf("unable to retrieve block %d for canonical hash: %s", block.NumberU64(), ch.Hex())
|
||||
t.Errorf("unable to retrieve block %d for canonical hash: %s", block.NumberU64(), ch.Hex())
|
||||
return
|
||||
}
|
||||
if fb.Hash() != block.Hash() {
|
||||
t.Fatalf("invalid block hash for block %d, want %s, got %s", block.NumberU64(), block.Hash().Hex(), fb.Hash().Hex())
|
||||
t.Errorf("invalid block hash for block %d, want %s, got %s", block.NumberU64(), block.Hash().Hex(), fb.Hash().Hex())
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,14 +80,17 @@ func TestMocker(t *testing.T) {
|
|||
var opts SubscribeOpts
|
||||
sub, err := client.SubscribeNetwork(events, opts)
|
||||
defer sub.Unsubscribe()
|
||||
//wait until all nodes are started and connected
|
||||
//store every node up event in a map (value is irrelevant, mimic Set datatype)
|
||||
|
||||
// wait until all nodes are started and connected
|
||||
// store every node up event in a map (value is irrelevant, mimic Set datatype)
|
||||
nodemap := make(map[discover.NodeID]bool)
|
||||
wg.Add(1)
|
||||
nodesComplete := false
|
||||
connCount := 0
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
for {
|
||||
defer wg.Done()
|
||||
|
||||
for connCount < (nodeCount-1)*2 {
|
||||
select {
|
||||
case event := <-events:
|
||||
//if the event is a node Up event only
|
||||
|
|
@ -102,14 +105,10 @@ func TestMocker(t *testing.T) {
|
|||
}
|
||||
} else if event.Conn != nil && nodesComplete {
|
||||
connCount += 1
|
||||
if connCount == (nodeCount-1)*2 {
|
||||
wg.Done()
|
||||
return
|
||||
}
|
||||
}
|
||||
case <-time.After(30 * time.Second):
|
||||
wg.Done()
|
||||
t.Fatalf("Timeout waiting for nodes being started up!")
|
||||
t.Errorf("Timeout waiting for nodes being started up!")
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ import (
|
|||
mrand "math/rand"
|
||||
"net"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -72,7 +71,6 @@ var keys = []string{
|
|||
}
|
||||
|
||||
type TestData struct {
|
||||
started int64
|
||||
counter [NumNodes]int
|
||||
mutex sync.RWMutex
|
||||
}
|
||||
|
|
@ -226,14 +224,9 @@ func initialize(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
startServer(t, node.server)
|
||||
nodes[i] = &node
|
||||
}
|
||||
|
||||
for i := 0; i < NumNodes; i++ {
|
||||
go startServer(t, nodes[i].server)
|
||||
}
|
||||
|
||||
waitForServersToStart(t)
|
||||
}
|
||||
|
||||
func startServer(t *testing.T, s *p2p.Server) {
|
||||
|
|
@ -241,8 +234,6 @@ func startServer(t *testing.T, s *p2p.Server) {
|
|||
if err != nil {
|
||||
t.Fatalf("failed to start the fisrt server.")
|
||||
}
|
||||
|
||||
atomic.AddInt64(&result.started, 1)
|
||||
}
|
||||
|
||||
func stopServers() {
|
||||
|
|
@ -500,16 +491,3 @@ func checkBloomFilterExchange(t *testing.T) {
|
|||
time.Sleep(50 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
func waitForServersToStart(t *testing.T) {
|
||||
const iterations = 200
|
||||
var started int64
|
||||
for j := 0; j < iterations; j++ {
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
started = atomic.LoadInt64(&result.started)
|
||||
if started == NumNodes {
|
||||
return
|
||||
}
|
||||
}
|
||||
t.Fatalf("Failed to start all the servers, running: %d", started)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue