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)
|
||||
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:
|
||||
//
|
||||
// event: <event>
|
||||
|
|
@ -455,6 +449,7 @@ func (s *Server) StreamNetworkEvents(w http.ResponseWriter, req *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
clientGone := req.Context().Done()
|
||||
for {
|
||||
select {
|
||||
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-Methods", "GET, POST, PUT, DELETE, OPTIONS")
|
||||
|
||||
ctx := context.Background()
|
||||
ctx := req.Context()
|
||||
|
||||
if id := params.ByName("nodeid"); id != "" {
|
||||
var nodeID enode.ID
|
||||
|
|
|
|||
|
|
@ -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[enode.ID]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 isNodeUp(event) {
|
||||
|
|
@ -99,14 +102,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
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
|
|
|||
|
|
@ -81,11 +81,13 @@ func TestSnapshot(t *testing.T) {
|
|||
|
||||
// connect nodes in a ring
|
||||
// spawn separate thread to avoid deadlock in the event listeners
|
||||
connectErr := make(chan error, 1)
|
||||
go func() {
|
||||
for i, id := range ids {
|
||||
peerID := ids[(i+1)%len(ids)]
|
||||
if err := network.Connect(id, peerID); err != nil {
|
||||
t.Fatal(err)
|
||||
connectErr <- err
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
|
@ -100,9 +102,10 @@ OUTER:
|
|||
select {
|
||||
case <-ctx.Done():
|
||||
t.Fatal(ctx.Err())
|
||||
case err := <-connectErr:
|
||||
t.Fatal(err)
|
||||
case ev := <-evC:
|
||||
if ev.Type == EventTypeConn && !ev.Control {
|
||||
|
||||
// fail on any disconnect
|
||||
if !ev.Conn.Up {
|
||||
t.Fatalf("unexpected disconnect: %v -> %v", ev.Conn.One, ev.Conn.Other)
|
||||
|
|
|
|||
Loading…
Reference in a new issue