From 03d2aa360f63b2a945b3510800cb53aea7791b0d Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 9 May 2018 09:20:40 +0200 Subject: [PATCH] lnd_test: fix flake from routing hints for inactive channel This commit attempts to fix a flake we have seen, where a routing hints for an inactive channel was unexpectedly added to the invoice. This happened because of a race between shutting down the endpoint of this channel (Eve) and creating the invoice. This commit fixes this by moving the call to AddInvoice with corresponding route hint check inside a WaitPredicate. --- lnd_test.go | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/lnd_test.go b/lnd_test.go index 2e820887c..eb46f8188 100644 --- a/lnd_test.go +++ b/lnd_test.go @@ -3433,23 +3433,27 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) { Private: true, } - resp, err := net.Alice.AddInvoice(ctxb, invoice) - if err != nil { - t.Fatalf("unable to add invoice: %v", err) - } - - // We'll decode the invoice's payment request to determine which - // channels were used as routing hints. - payReq := &lnrpc.PayReqString{resp.PaymentRequest} - decoded, err := net.Alice.DecodePayReq(ctxb, payReq) - if err != nil { - t.Fatalf("unable to decode payment request: %v", err) - } - // Due to the way the channels were set up above, the channel between // Alice and Bob should be the only channel used as a routing hint. var predErr error + var decoded *lnrpc.PayReq err = lntest.WaitPredicate(func() bool { + resp, err := net.Alice.AddInvoice(ctxb, invoice) + if err != nil { + predErr = fmt.Errorf("unable to add invoice: %v", err) + return false + } + + // We'll decode the invoice's payment request to determine which + // channels were used as routing hints. + payReq := &lnrpc.PayReqString{resp.PaymentRequest} + decoded, err = net.Alice.DecodePayReq(ctxb, payReq) + if err != nil { + predErr = fmt.Errorf("unable to decode payment "+ + "request: %v", err) + return false + } + if len(decoded.RouteHints) != 1 { predErr = fmt.Errorf("expected one route hint, got %d", len(decoded.RouteHints))