Skip to content

Commit 1b9c5b3

Browse files
authored
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.
1 parent 57d4898 commit 1b9c5b3

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

common/mclock/simclock_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func TestSimulatedSleep(t *testing.T) {
9696
var (
9797
c Simulated
9898
timeout = 1 * time.Hour
99-
done = make(chan AbsTime)
99+
done = make(chan AbsTime, 1)
100100
)
101101
go func() {
102102
c.Sleep(timeout)

eth/handler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ func TestBroadcastMalformedBlock(t *testing.T) {
670670
malformedEverything.TxHash[0]++
671671

672672
// Keep listening to broadcasts and notify if any arrives
673-
notify := make(chan struct{})
673+
notify := make(chan struct{}, 1)
674674
go func() {
675675
if _, err := sink.app.ReadMsg(); err == nil {
676676
notify <- struct{}{}

p2p/server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ func TestServerInboundThrottle(t *testing.T) {
550550
conn.Close()
551551

552552
// Dial again. This time the server should close the connection immediately.
553-
connClosed := make(chan struct{})
553+
connClosed := make(chan struct{}, 1)
554554
conn, err = net.DialTimeout("tcp", srv.ListenAddr, timeout)
555555
if err != nil {
556556
t.Fatalf("could not dial: %v", err)

rpc/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ func TestClientSubscribeClose(t *testing.T) {
297297

298298
var (
299299
nc = make(chan int)
300-
errc = make(chan error)
300+
errc = make(chan error, 1)
301301
sub *ClientSubscription
302302
err error
303303
)

0 commit comments

Comments
 (0)