htlcswitch: return time result from bidirection test

This commit is contained in:
Andrey Samokhvalov 2017-06-25 20:27:36 +03:00 committed by andrew.shvv
parent 2acb2bb373
commit c13e36617c
2 changed files with 53 additions and 14 deletions

@ -10,6 +10,8 @@ import (
"io" "io"
"math"
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
"github.com/go-errors/errors" "github.com/go-errors/errors"
"github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet"
@ -165,40 +167,73 @@ func TestChannelLinkBidirectionalOneHopPayments(t *testing.T) {
n.firstBobChannelLink) n.firstBobChannelLink)
_, _, hopsBackwards := generateHops(amt, n.aliceChannelLink) _, _, 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 // Send max available payment number in both sides, thereby testing
// the property of channel link to cope with overflowing. // the property of channel link to cope with overflowing.
errChan := make(chan error) resultChan := make(chan *result)
count := 2 * lnwallet.MaxHTLCNumber count := 2 * lnwallet.MaxHTLCNumber
for i := 0; i < count/2; i++ { for i := 0; i < count/2; i++ {
go func() { go func(i int) {
_, err := n.makePayment(n.aliceServer, n.bobServer, r := &result{
start: time.Now(),
number: i,
sender: "alice",
}
_, r.err = n.makePayment(n.aliceServer, n.bobServer,
n.bobServer.PubKey(), hopsForwards, amt, htlcAmt, n.bobServer.PubKey(), hopsForwards, amt, htlcAmt,
totalTimelock) totalTimelock)
errChan <- err resultChan <- r
}() }(i)
} }
for i := 0; i < count/2; i++ { for i := 0; i < count/2; i++ {
go func() { go func(i int) {
_, err := n.makePayment(n.bobServer, n.aliceServer, r := &result{
start: time.Now(),
number: i,
sender: "bob",
}
_, r.err = n.makePayment(n.bobServer, n.aliceServer,
n.aliceServer.PubKey(), hopsBackwards, amt, htlcAmt, n.aliceServer.PubKey(), hopsBackwards, amt, htlcAmt,
totalTimelock) 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 // Check that alice invoice was settled and bandwidth of HTLC
// links was changed. // links was changed.
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
select { select {
case err := <-errChan: case r := <-resultChan:
if err != nil { if r.err != nil {
t.Fatalf("unable to make the payment: %v", err) 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): case <-time.After(30 * time.Second):
t.Fatalf("timeout: (%v/%v)", i+1, count) t.Fatalf("timeout: (%v/%v)", i+1, count)
} }
} }
// At the end Bob and Alice balances should be the same as previous, // 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() { if bobBandwidthBefore != n.firstBobChannelLink.Bandwidth() {
t.Fatal("bob bandwidth shouldn't have changed") 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 // TestChannelLinkMultiHopPayment checks the ability to send payment over two

@ -425,7 +425,7 @@ func (n *threeHopNetwork) makePayment(sendingPeer, receivingPeer Peer,
select { select {
case err := <-errChan: case err := <-errChan:
return invoice, err 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") return invoice, errors.New("htlc was not settled in time")
} }
} }