routing/test: add check that sendpayment completes

As is, we don't check that our SendPayment call in
TestRouterPaymentStateMachine completes. This makes it easier
to create malformed tests that just run through steps but leave
the SendPayment call hanging. This commit adds a check that we
have completed our payment to help catch tests like this. We
also remove an unused quit channel.
This commit is contained in:
carla 2021-04-23 08:39:36 +02:00
parent 5a82340a03
commit cb927e89b0
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91

@ -564,9 +564,6 @@ func TestRouterPaymentStateMachine(t *testing.T) {
control.failPayment = make(chan failPaymentArgs, 20)
control.fetchInFlight = make(chan struct{}, 20)
quit := make(chan struct{})
defer close(quit)
// setupRouter is a helper method that creates and starts the router in
// the desired configuration for this test.
setupRouter := func() (*ChannelRouter, chan error,
@ -672,9 +669,11 @@ func TestRouterPaymentStateMachine(t *testing.T) {
// Send the payment. Since this is new payment hash, the
// information should be registered with the ControlTower.
paymentResult := make(chan error)
done := make(chan struct{})
go func() {
_, _, err := router.SendPayment(&payment)
paymentResult <- err
close(done)
}()
var resendResult chan error
@ -894,5 +893,11 @@ func TestRouterPaymentStateMachine(t *testing.T) {
t.Fatalf("unknown step %v", step)
}
}
select {
case <-done:
case <-time.After(testTimeout):
t.Fatalf("SendPayment didn't exit")
}
}
}