From eb3e02b64f974ffb5aa731b660775a01f8d6b827 Mon Sep 17 00:00:00 2001 From: BurtonQin Date: Thu, 13 Feb 2020 18:19:32 +0800 Subject: [PATCH] common, eth, p2p, rpc: add 1 buffer to fix goroutine leak in tests --- common/mclock/simclock_test.go | 2 +- eth/handler_test.go | 2 +- p2p/server_test.go | 4 ++-- rpc/client_test.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/common/mclock/simclock_test.go b/common/mclock/simclock_test.go index 94aa4f2b39ea..48f3fd56a06a 100644 --- a/common/mclock/simclock_test.go +++ b/common/mclock/simclock_test.go @@ -96,7 +96,7 @@ func TestSimulatedSleep(t *testing.T) { var ( c Simulated timeout = 1 * time.Hour - done = make(chan AbsTime) + done = make(chan AbsTime, 1) ) go func() { c.Sleep(timeout) diff --git a/eth/handler_test.go b/eth/handler_test.go index 354cbc068c14..dd4382a8d512 100644 --- a/eth/handler_test.go +++ b/eth/handler_test.go @@ -677,7 +677,7 @@ func TestBroadcastMalformedBlock(t *testing.T) { malformedEverything.TxHash[0]++ // Keep listening to broadcasts and notify if any arrives - notify := make(chan struct{}) + notify := make(chan struct{}, 1) go func() { if _, err := sink.app.ReadMsg(); err == nil { notify <- struct{}{} diff --git a/p2p/server_test.go b/p2p/server_test.go index 383445c83388..e2fd67c991b3 100644 --- a/p2p/server_test.go +++ b/p2p/server_test.go @@ -131,7 +131,7 @@ func TestServerDial(t *testing.T) { t.Fatalf("could not setup listener: %v", err) } defer listener.Close() - accepted := make(chan net.Conn) + accepted := make(chan net.Conn, 1) go func() { conn, err := listener.Accept() if err != nil { @@ -670,7 +670,7 @@ func TestServerInboundThrottle(t *testing.T) { conn.Close() // Dial again. This time the server should close the connection immediately. - connClosed := make(chan struct{}) + connClosed := make(chan struct{}, 1) conn, err = net.DialTimeout("tcp", srv.ListenAddr, timeout) if err != nil { t.Fatalf("could not dial: %v", err) diff --git a/rpc/client_test.go b/rpc/client_test.go index 9c7f72053b41..0287dad08838 100644 --- a/rpc/client_test.go +++ b/rpc/client_test.go @@ -297,7 +297,7 @@ func TestClientSubscribeClose(t *testing.T) { var ( nc = make(chan int) - errc = make(chan error) + errc = make(chan error, 1) sub *ClientSubscription err error )