From 5f1647f7655c5bfe6ff37aeed7be3875951948e0 Mon Sep 17 00:00:00 2001 From: BurtonQin Date: Sun, 22 May 2022 06:25:54 -0400 Subject: [PATCH] p2p: use buffered channel to avoid goroutine leak in tests --- p2p/discover/v4_udp_test.go | 2 +- p2p/dnsdisc/client_test.go | 2 +- p2p/simulations/examples/ping-pong.go | 2 +- p2p/simulations/http_test.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/p2p/discover/v4_udp_test.go b/p2p/discover/v4_udp_test.go index e36912f010ae..9869244cbf6c 100644 --- a/p2p/discover/v4_udp_test.go +++ b/p2p/discover/v4_udp_test.go @@ -312,7 +312,7 @@ func TestUDPv4_findnodeMultiReply(t *testing.T) { test.table.db.UpdateLastPingReceived(rid, test.remoteaddr.IP, time.Now()) // queue a pending findnode request - resultc, errc := make(chan []*node), make(chan error) + resultc, errc := make(chan []*node, 1), make(chan error, 1) go func() { rid := encodePubkey(&test.remotekey.PublicKey).id() ns, err := test.udp.findnode(rid, test.remoteaddr, testTarget) diff --git a/p2p/dnsdisc/client_test.go b/p2p/dnsdisc/client_test.go index 9320dd667a94..361535d24b69 100644 --- a/p2p/dnsdisc/client_test.go +++ b/p2p/dnsdisc/client_test.go @@ -265,7 +265,7 @@ func TestIteratorEmptyTree(t *testing.T) { resolver.add(tree1.ToTXT("n")) // Start the iterator. - node := make(chan *enode.Node) + node := make(chan *enode.Node, 1) it, err := c.NewIterator(url) if err != nil { t.Fatal(err) diff --git a/p2p/simulations/examples/ping-pong.go b/p2p/simulations/examples/ping-pong.go index 2f4c56054876..d9b51dc09bb0 100644 --- a/p2p/simulations/examples/ping-pong.go +++ b/p2p/simulations/examples/ping-pong.go @@ -139,7 +139,7 @@ const ( func (p *pingPongService) Run(peer *p2p.Peer, rw p2p.MsgReadWriter) error { log := p.log.New("peer.id", peer.ID()) - errC := make(chan error) + errC := make(chan error, 1) go func() { for range time.Tick(10 * time.Second) { log.Info("sending ping") diff --git a/p2p/simulations/http_test.go b/p2p/simulations/http_test.go index f5172f3f23db..565f6b93698f 100644 --- a/p2p/simulations/http_test.go +++ b/p2p/simulations/http_test.go @@ -598,7 +598,7 @@ func TestHTTPSnapshot(t *testing.T) { network, s := testHTTPServer(t) defer s.Close() - var eventsDone = make(chan struct{}) + var eventsDone = make(chan struct{}, 1) count := 1 eventsDoneChan := make(chan *Event) eventSub := network.Events().Subscribe(eventsDoneChan)