Merge pull request #3646 from alrs/fix-routing-test-goroutine

routing: fix use of T.Fatal() in test goroutine
This commit is contained in:
Olaoluwa Osuntokun 2019-10-29 20:00:30 -07:00 committed by GitHub
commit 0fdfb4d76f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,6 +2,7 @@ package routing
import ( import (
"bytes" "bytes"
"errors"
"fmt" "fmt"
"image/color" "image/color"
"math" "math"
@ -2978,13 +2979,14 @@ func TestRouterPaymentStateMachine(t *testing.T) {
// On startup, the router should fetch all pending payments // On startup, the router should fetch all pending payments
// from the ControlTower, so assert that here. // from the ControlTower, so assert that here.
didFetch := make(chan struct{}) errCh := make(chan error)
go func() { go func() {
close(errCh)
select { select {
case <-control.fetchInFlight: case <-control.fetchInFlight:
close(didFetch) return
case <-time.After(1 * time.Second): case <-time.After(1 * time.Second):
t.Fatalf("router did not fetch in flight " + errCh <- errors.New("router did not fetch in flight " +
"payments") "payments")
} }
}() }()
@ -2994,7 +2996,10 @@ func TestRouterPaymentStateMachine(t *testing.T) {
} }
select { select {
case <-didFetch: case err := <-errCh:
if err != nil {
t.Fatalf("error in anonymous goroutine: %s", err)
}
case <-time.After(1 * time.Second): case <-time.After(1 * time.Second):
t.Fatalf("did not fetch in flight payments at startup") t.Fatalf("did not fetch in flight payments at startup")
} }