Unverified Commit 1b9c5b39 authored by Boqin Qin's avatar Boqin Qin Committed by GitHub

all: fix goroutine leaks in unit tests by adding 1-elem channel buffer (#20666)

This fixes a bunch of cases where a timeout in the test would leak
a goroutine.
parent 57d4898e
......@@ -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)
......
......@@ -670,7 +670,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{}{}
......
......@@ -550,7 +550,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)
......
......@@ -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
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment