From bb9bc9205a888a688f15efe58f003fd5497db195 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 17 Jun 2017 00:41:42 +0200 Subject: [PATCH] htlcswitch: run all unit tests in parallel --- htlcswitch/queue_test.go | 2 ++ htlcswitch/switch_test.go | 8 ++++++++ htlcswitch/test_utils.go | 15 ++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/htlcswitch/queue_test.go b/htlcswitch/queue_test.go index 91c18f4c..b317c075 100644 --- a/htlcswitch/queue_test.go +++ b/htlcswitch/queue_test.go @@ -13,6 +13,8 @@ import ( // waiting queue, by executing methods in seprate goroutines which operates // with the same data. func TestWaitingQueueThreadSafety(t *testing.T) { + t.Parallel() + q := newWaitingQueue() a := make([]btcutil.Amount, 1000) diff --git a/htlcswitch/switch_test.go b/htlcswitch/switch_test.go index a1df2dfd..6fe06234 100644 --- a/htlcswitch/switch_test.go +++ b/htlcswitch/switch_test.go @@ -30,6 +30,8 @@ var ( // TestSwitchForward checks the ability of htlc switch to forward add/settle // requests. func TestSwitchForward(t *testing.T) { + t.Parallel() + var packet *htlcPacket alicePeer := newMockServer(t, "alice") @@ -106,6 +108,8 @@ func TestSwitchForward(t *testing.T) { // TestSwitchCancel checks that if htlc was rejected we remove unused // circuits. func TestSwitchCancel(t *testing.T) { + t.Parallel() + var request *htlcPacket alicePeer := newMockServer(t, "alice") @@ -180,6 +184,8 @@ func TestSwitchCancel(t *testing.T) { // TestSwitchAddSamePayment tests that we send the payment with the same // payment hash. func TestSwitchAddSamePayment(t *testing.T) { + t.Parallel() + var request *htlcPacket alicePeer := newMockServer(t, "alice") @@ -279,6 +285,8 @@ func TestSwitchAddSamePayment(t *testing.T) { // TestSwitchSendPayment tests ability of htlc switch to respond to the // users when response is came back from channel link. func TestSwitchSendPayment(t *testing.T) { + t.Parallel() + alicePeer := newMockServer(t, "alice") aliceChannelLink := newMockChannelLink(chanID1, aliceChanID, alicePeer) diff --git a/htlcswitch/test_utils.go b/htlcswitch/test_utils.go index 214550c9..fbff7b10 100644 --- a/htlcswitch/test_utils.go +++ b/htlcswitch/test_utils.go @@ -315,7 +315,9 @@ type threeHopNetwork struct { globalPolicy ForwardingPolicy } -// generateHops... +// generateHops creates the per hop payload, the total amount to be sent, and +// also the time lock value needed to route a HTLC with the target amount over +// the specified path. func generateHops(payAmt btcutil.Amount, path ...*channelLink) (btcutil.Amount, uint32, []ForwardingInfo) { @@ -328,19 +330,27 @@ func generateHops(payAmt btcutil.Amount, hops := make([]ForwardingInfo, len(path)) for i := len(path) - 1; i >= 0; i-- { + // If this is the last hop, then the next hop is the special + // "exit node". Otherwise, we look to the "prior" hop. nextHop := exitHop if i != len(path)-1 { nextHop = path[i+1].channel.ShortChanID() } + // If this is the last, hop, then the time lock will be their + // specified delta policy. timeLock := lastHop.cfg.FwrdingPolicy.TimeLockDelta totalTimelock += timeLock + // Otherwise, the outgoing time lock should be the incoming + // timelock minus their specified delta. if i != len(path)-1 { delta := path[i].cfg.FwrdingPolicy.TimeLockDelta timeLock = totalTimelock - delta } + // Finally, we'll need to calculate the amount to forward. For + // the last hop, it's just the payment amount. amount := payAmt if i != len(path)-1 { prevHop := hops[i+1] @@ -349,6 +359,9 @@ func generateHops(payAmt btcutil.Amount, fee := ExpectedFee(path[i].cfg.FwrdingPolicy, prevAmount) runningAmt += fee + // If the this the first hop, then we don't need to + // apply any fee, otherwise, the amount to forward + // needs to take into account the fees. if i == 0 { amount = prevAmount } else {