From c13e36617cc341d973501399df7d1577916614fa Mon Sep 17 00:00:00 2001 From: Andrey Samokhvalov Date: Sun, 25 Jun 2017 20:27:36 +0300 Subject: [PATCH] htlcswitch: return time result from bidirection test --- htlcswitch/link_test.go | 65 ++++++++++++++++++++++++++++++++-------- htlcswitch/test_utils.go | 2 +- 2 files changed, 53 insertions(+), 14 deletions(-) diff --git a/htlcswitch/link_test.go b/htlcswitch/link_test.go index eab46eea..a2b6235d 100644 --- a/htlcswitch/link_test.go +++ b/htlcswitch/link_test.go @@ -10,6 +10,8 @@ import ( "io" + "math" + "github.com/davecgh/go-spew/spew" "github.com/go-errors/errors" "github.com/lightningnetwork/lnd/lnwallet" @@ -165,40 +167,73 @@ func TestChannelLinkBidirectionalOneHopPayments(t *testing.T) { n.firstBobChannelLink) _, _, hopsBackwards := generateHops(amt, n.aliceChannelLink) + type result struct { + err error + start time.Time + number int + sender string + } + // Send max available payment number in both sides, thereby testing // the property of channel link to cope with overflowing. - errChan := make(chan error) + resultChan := make(chan *result) count := 2 * lnwallet.MaxHTLCNumber for i := 0; i < count/2; i++ { - go func() { - _, err := n.makePayment(n.aliceServer, n.bobServer, + go func(i int) { + r := &result{ + start: time.Now(), + number: i, + sender: "alice", + } + + _, r.err = n.makePayment(n.aliceServer, n.bobServer, n.bobServer.PubKey(), hopsForwards, amt, htlcAmt, totalTimelock) - errChan <- err - }() + resultChan <- r + }(i) } for i := 0; i < count/2; i++ { - go func() { - _, err := n.makePayment(n.bobServer, n.aliceServer, + go func(i int) { + r := &result{ + start: time.Now(), + number: i, + sender: "bob", + } + + _, r.err = n.makePayment(n.bobServer, n.aliceServer, n.aliceServer.PubKey(), hopsBackwards, amt, htlcAmt, totalTimelock) - errChan <- err - }() + resultChan <- r + }(i) } + maxDelay := time.Duration(0) + minDelay := time.Duration(math.MaxInt64) + averageDelay := time.Duration(0) + // Check that alice invoice was settled and bandwidth of HTLC // links was changed. for i := 0; i < count; i++ { select { - case err := <-errChan: - if err != nil { - t.Fatalf("unable to make the payment: %v", err) + case r := <-resultChan: + if r.err != nil { + t.Fatalf("unable to make the payment: %v", r.err) } + + delay := time.Since(r.start) + if delay > maxDelay { + maxDelay = delay + } + + if delay < minDelay { + minDelay = delay + } + averageDelay += delay + case <-time.After(30 * time.Second): t.Fatalf("timeout: (%v/%v)", i+1, count) } - } // At the end Bob and Alice balances should be the same as previous, @@ -210,6 +245,10 @@ func TestChannelLinkBidirectionalOneHopPayments(t *testing.T) { if bobBandwidthBefore != n.firstBobChannelLink.Bandwidth() { t.Fatal("bob bandwidth shouldn't have changed") } + + t.Logf("Max waiting: %v", maxDelay) + t.Logf("Min waiting: %v", minDelay) + t.Logf("Average waiting: %v", time.Duration(int(averageDelay)/count)) } // TestChannelLinkMultiHopPayment checks the ability to send payment over two diff --git a/htlcswitch/test_utils.go b/htlcswitch/test_utils.go index bffd51a1..8c2a6d78 100644 --- a/htlcswitch/test_utils.go +++ b/htlcswitch/test_utils.go @@ -425,7 +425,7 @@ func (n *threeHopNetwork) makePayment(sendingPeer, receivingPeer Peer, select { case err := <-errChan: return invoice, err - case <-time.After(20 * time.Second): + case <-time.After(50 * time.Second): return invoice, errors.New("htlc was not settled in time") } }