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.
This commit is contained in:
Johan T. Halseth 2018-05-09 09:20:40 +02:00
parent ddcbb40898
commit 03d2aa360f
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -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))