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:
1 file changed
+17
-13
+17
-13
@@ -3433,23 +3433,27 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
Private: true,
|
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
|
// 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.
|
// Alice and Bob should be the only channel used as a routing hint.
|
||||||
var predErr error
|
var predErr error
|
||||||
|
var decoded *lnrpc.PayReq
|
||||||
err = lntest.WaitPredicate(func() bool {
|
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 {
|
if len(decoded.RouteHints) != 1 {
|
||||||
predErr = fmt.Errorf("expected one route hint, got %d",
|
predErr = fmt.Errorf("expected one route hint, got %d",
|
||||||
len(decoded.RouteHints))
|
len(decoded.RouteHints))
|
||||||
|
|||||||
Reference in new issue
Block a user