From 6254c53a4a11446d5d06170340a3d78036bf49bd Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Tue, 29 Oct 2019 13:21:53 -0700 Subject: [PATCH] routing: fix use of T.Fatal() in test goroutine --- routing/router_test.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/routing/router_test.go b/routing/router_test.go index fb73a000..b2b9e79c 100644 --- a/routing/router_test.go +++ b/routing/router_test.go @@ -2,6 +2,7 @@ package routing import ( "bytes" + "errors" "fmt" "image/color" "math" @@ -2978,13 +2979,14 @@ func TestRouterPaymentStateMachine(t *testing.T) { // On startup, the router should fetch all pending payments // from the ControlTower, so assert that here. - didFetch := make(chan struct{}) + errCh := make(chan error) go func() { + close(errCh) select { case <-control.fetchInFlight: - close(didFetch) + return case <-time.After(1 * time.Second): - t.Fatalf("router did not fetch in flight " + + errCh <- errors.New("router did not fetch in flight " + "payments") } }() @@ -2994,7 +2996,10 @@ func TestRouterPaymentStateMachine(t *testing.T) { } select { - case <-didFetch: + case err := <-errCh: + if err != nil { + t.Fatalf("error in anonymous goroutine: %s", err) + } case <-time.After(1 * time.Second): t.Fatalf("did not fetch in flight payments at startup") }