From cb927e89b02a5d33511b93626d3c2607bdcaabc2 Mon Sep 17 00:00:00 2001 From: carla Date: Fri, 23 Apr 2021 08:39:36 +0200 Subject: [PATCH] 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. --- routing/payment_lifecycle_test.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/routing/payment_lifecycle_test.go b/routing/payment_lifecycle_test.go index e83ac17f..70346966 100644 --- a/routing/payment_lifecycle_test.go +++ b/routing/payment_lifecycle_test.go @@ -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") + } } }