mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
p2p/simulations: fix staticcheck warnings
This commit is contained in:
parent
563410573d
commit
2eb7d945da
3 changed files with 16 additions and 19 deletions
|
|
@ -384,12 +384,6 @@ func (s *Server) StreamNetworkEvents(w http.ResponseWriter, req *http.Request) {
|
||||||
sub := s.network.events.Subscribe(events)
|
sub := s.network.events.Subscribe(events)
|
||||||
defer sub.Unsubscribe()
|
defer sub.Unsubscribe()
|
||||||
|
|
||||||
// stop the stream if the client goes away
|
|
||||||
var clientGone <-chan bool
|
|
||||||
if cn, ok := w.(http.CloseNotifier); ok {
|
|
||||||
clientGone = cn.CloseNotify()
|
|
||||||
}
|
|
||||||
|
|
||||||
// write writes the given event and data to the stream like:
|
// write writes the given event and data to the stream like:
|
||||||
//
|
//
|
||||||
// event: <event>
|
// event: <event>
|
||||||
|
|
@ -455,6 +449,7 @@ func (s *Server) StreamNetworkEvents(w http.ResponseWriter, req *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clientGone := req.Context().Done()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case event := <-events:
|
case event := <-events:
|
||||||
|
|
@ -710,7 +705,7 @@ func (s *Server) wrapHandler(handler http.HandlerFunc) httprouter.Handle {
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
|
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := req.Context()
|
||||||
|
|
||||||
if id := params.ByName("nodeid"); id != "" {
|
if id := params.ByName("nodeid"); id != "" {
|
||||||
var nodeID enode.ID
|
var nodeID enode.ID
|
||||||
|
|
|
||||||
|
|
@ -80,14 +80,17 @@ func TestMocker(t *testing.T) {
|
||||||
var opts SubscribeOpts
|
var opts SubscribeOpts
|
||||||
sub, err := client.SubscribeNetwork(events, opts)
|
sub, err := client.SubscribeNetwork(events, opts)
|
||||||
defer sub.Unsubscribe()
|
defer sub.Unsubscribe()
|
||||||
|
|
||||||
// wait until all nodes are started and connected
|
// wait until all nodes are started and connected
|
||||||
// store every node up event in a map (value is irrelevant, mimic Set datatype)
|
// store every node up event in a map (value is irrelevant, mimic Set datatype)
|
||||||
nodemap := make(map[enode.ID]bool)
|
nodemap := make(map[enode.ID]bool)
|
||||||
wg.Add(1)
|
|
||||||
nodesComplete := false
|
nodesComplete := false
|
||||||
connCount := 0
|
connCount := 0
|
||||||
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
defer wg.Done()
|
||||||
|
|
||||||
|
for connCount < (nodeCount-1)*2 {
|
||||||
select {
|
select {
|
||||||
case event := <-events:
|
case event := <-events:
|
||||||
if isNodeUp(event) {
|
if isNodeUp(event) {
|
||||||
|
|
@ -99,14 +102,10 @@ func TestMocker(t *testing.T) {
|
||||||
}
|
}
|
||||||
} else if event.Conn != nil && nodesComplete {
|
} else if event.Conn != nil && nodesComplete {
|
||||||
connCount += 1
|
connCount += 1
|
||||||
if connCount == (nodeCount-1)*2 {
|
|
||||||
wg.Done()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case <-time.After(30 * time.Second):
|
case <-time.After(30 * time.Second):
|
||||||
wg.Done()
|
t.Errorf("Timeout waiting for nodes being started up!")
|
||||||
t.Fatalf("Timeout waiting for nodes being started up!")
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
|
||||||
|
|
@ -81,11 +81,13 @@ func TestSnapshot(t *testing.T) {
|
||||||
|
|
||||||
// connect nodes in a ring
|
// connect nodes in a ring
|
||||||
// spawn separate thread to avoid deadlock in the event listeners
|
// spawn separate thread to avoid deadlock in the event listeners
|
||||||
|
connectErr := make(chan error, 1)
|
||||||
go func() {
|
go func() {
|
||||||
for i, id := range ids {
|
for i, id := range ids {
|
||||||
peerID := ids[(i+1)%len(ids)]
|
peerID := ids[(i+1)%len(ids)]
|
||||||
if err := network.Connect(id, peerID); err != nil {
|
if err := network.Connect(id, peerID); err != nil {
|
||||||
t.Fatal(err)
|
connectErr <- err
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
@ -100,9 +102,10 @@ OUTER:
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
t.Fatal(ctx.Err())
|
t.Fatal(ctx.Err())
|
||||||
|
case err := <-connectErr:
|
||||||
|
t.Fatal(err)
|
||||||
case ev := <-evC:
|
case ev := <-evC:
|
||||||
if ev.Type == EventTypeConn && !ev.Control {
|
if ev.Type == EventTypeConn && !ev.Control {
|
||||||
|
|
||||||
// fail on any disconnect
|
// fail on any disconnect
|
||||||
if !ev.Conn.Up {
|
if !ev.Conn.Up {
|
||||||
t.Fatalf("unexpected disconnect: %v -> %v", ev.Conn.One, ev.Conn.Other)
|
t.Fatalf("unexpected disconnect: %v -> %v", ev.Conn.One, ev.Conn.Other)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue