From a68155545c9a001d990dba35ae4139bfa6064ffe Mon Sep 17 00:00:00 2001 From: carla Date: Fri, 23 Apr 2021 08:39:42 +0200 Subject: [PATCH] routing/test: use half shard for single success case Update our single shard success case to use a route which splits the payment amount in half. This change still tests the case where reveal of the preimage counts as a success, even if we don't have the full amount. This change is made to cut down on potential races in this test case. While we are waiting for collectResultAsync to report a success, the payment lifecycle will continue trying to dispatch shards. In the case where we send 1/4 of the payment amount, we send 1 or 2 more shards, depending on how long collectAsync takes. Reducing this test to send 1/2 of the payment amount means that we will always only try one more shard before waiting for our shard. --- routing/payment_lifecycle_test.go | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/routing/payment_lifecycle_test.go b/routing/payment_lifecycle_test.go index 80c4c281..4fc5a015 100644 --- a/routing/payment_lifecycle_test.go +++ b/routing/payment_lifecycle_test.go @@ -190,6 +190,9 @@ func TestRouterPaymentStateMachine(t *testing.T) { t.Fatalf("unable to create route: %v", err) } + halfShard, err := createTestRoute(paymentAmt/2, testGraph.aliasMap) + require.NoError(t, err, "unable to create half route") + shard, err := createTestRoute(paymentAmt/4, testGraph.aliasMap) if err != nil { t.Fatalf("unable to create route: %v", err) @@ -501,10 +504,8 @@ func TestRouterPaymentStateMachine(t *testing.T) { }, }, { - // An MP payment scenario where 3 of the shards fail. - // However the last shard settle, which means we get - // the preimage and should consider the overall payment - // a success. + // An MP payment scenario where one of the shards fails, + // but we still receive a single success shard. name: "MP one shard success", steps: []string{ @@ -518,30 +519,18 @@ func TestRouterPaymentStateMachine(t *testing.T) { routerRegisterAttempt, sendToSwitchSuccess, - // shard 2 - routerRegisterAttempt, - sendToSwitchSuccess, - - // shard 3 - routerRegisterAttempt, - sendToSwitchSuccess, - - // 3 shards fail, and should be failed by the + // shard 0 fails, and should be failed by the // router. getPaymentResultTempFailure, - getPaymentResultTempFailure, - getPaymentResultTempFailure, - routerFailAttempt, - routerFailAttempt, routerFailAttempt, - // The fourth shard succeed against all odds, + // The second shard succeed against all odds, // making the overall payment succeed. getPaymentResultSuccess, routerSettleAttempt, paymentSuccess, }, - routes: []*route.Route{shard, shard, shard, shard}, + routes: []*route.Route{halfShard, halfShard}, }, { // An MP payment scenario a shard fail with a terminal