htlcswitch: run all unit tests in parallel
This commit is contained in:
parent
a43b5658bb
commit
bb9bc9205a
@ -13,6 +13,8 @@ import (
|
|||||||
// waiting queue, by executing methods in seprate goroutines which operates
|
// waiting queue, by executing methods in seprate goroutines which operates
|
||||||
// with the same data.
|
// with the same data.
|
||||||
func TestWaitingQueueThreadSafety(t *testing.T) {
|
func TestWaitingQueueThreadSafety(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
q := newWaitingQueue()
|
q := newWaitingQueue()
|
||||||
|
|
||||||
a := make([]btcutil.Amount, 1000)
|
a := make([]btcutil.Amount, 1000)
|
||||||
|
@ -30,6 +30,8 @@ var (
|
|||||||
// TestSwitchForward checks the ability of htlc switch to forward add/settle
|
// TestSwitchForward checks the ability of htlc switch to forward add/settle
|
||||||
// requests.
|
// requests.
|
||||||
func TestSwitchForward(t *testing.T) {
|
func TestSwitchForward(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
var packet *htlcPacket
|
var packet *htlcPacket
|
||||||
|
|
||||||
alicePeer := newMockServer(t, "alice")
|
alicePeer := newMockServer(t, "alice")
|
||||||
@ -106,6 +108,8 @@ func TestSwitchForward(t *testing.T) {
|
|||||||
// TestSwitchCancel checks that if htlc was rejected we remove unused
|
// TestSwitchCancel checks that if htlc was rejected we remove unused
|
||||||
// circuits.
|
// circuits.
|
||||||
func TestSwitchCancel(t *testing.T) {
|
func TestSwitchCancel(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
var request *htlcPacket
|
var request *htlcPacket
|
||||||
|
|
||||||
alicePeer := newMockServer(t, "alice")
|
alicePeer := newMockServer(t, "alice")
|
||||||
@ -180,6 +184,8 @@ func TestSwitchCancel(t *testing.T) {
|
|||||||
// TestSwitchAddSamePayment tests that we send the payment with the same
|
// TestSwitchAddSamePayment tests that we send the payment with the same
|
||||||
// payment hash.
|
// payment hash.
|
||||||
func TestSwitchAddSamePayment(t *testing.T) {
|
func TestSwitchAddSamePayment(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
var request *htlcPacket
|
var request *htlcPacket
|
||||||
|
|
||||||
alicePeer := newMockServer(t, "alice")
|
alicePeer := newMockServer(t, "alice")
|
||||||
@ -279,6 +285,8 @@ func TestSwitchAddSamePayment(t *testing.T) {
|
|||||||
// TestSwitchSendPayment tests ability of htlc switch to respond to the
|
// TestSwitchSendPayment tests ability of htlc switch to respond to the
|
||||||
// users when response is came back from channel link.
|
// users when response is came back from channel link.
|
||||||
func TestSwitchSendPayment(t *testing.T) {
|
func TestSwitchSendPayment(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
alicePeer := newMockServer(t, "alice")
|
alicePeer := newMockServer(t, "alice")
|
||||||
aliceChannelLink := newMockChannelLink(chanID1, aliceChanID, alicePeer)
|
aliceChannelLink := newMockChannelLink(chanID1, aliceChanID, alicePeer)
|
||||||
|
|
||||||
|
@ -315,7 +315,9 @@ type threeHopNetwork struct {
|
|||||||
globalPolicy ForwardingPolicy
|
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,
|
func generateHops(payAmt btcutil.Amount,
|
||||||
path ...*channelLink) (btcutil.Amount, uint32, []ForwardingInfo) {
|
path ...*channelLink) (btcutil.Amount, uint32, []ForwardingInfo) {
|
||||||
|
|
||||||
@ -328,19 +330,27 @@ func generateHops(payAmt btcutil.Amount,
|
|||||||
|
|
||||||
hops := make([]ForwardingInfo, len(path))
|
hops := make([]ForwardingInfo, len(path))
|
||||||
for i := len(path) - 1; i >= 0; i-- {
|
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
|
nextHop := exitHop
|
||||||
if i != len(path)-1 {
|
if i != len(path)-1 {
|
||||||
nextHop = path[i+1].channel.ShortChanID()
|
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
|
timeLock := lastHop.cfg.FwrdingPolicy.TimeLockDelta
|
||||||
totalTimelock += timeLock
|
totalTimelock += timeLock
|
||||||
|
|
||||||
|
// Otherwise, the outgoing time lock should be the incoming
|
||||||
|
// timelock minus their specified delta.
|
||||||
if i != len(path)-1 {
|
if i != len(path)-1 {
|
||||||
delta := path[i].cfg.FwrdingPolicy.TimeLockDelta
|
delta := path[i].cfg.FwrdingPolicy.TimeLockDelta
|
||||||
timeLock = totalTimelock - delta
|
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
|
amount := payAmt
|
||||||
if i != len(path)-1 {
|
if i != len(path)-1 {
|
||||||
prevHop := hops[i+1]
|
prevHop := hops[i+1]
|
||||||
@ -349,6 +359,9 @@ func generateHops(payAmt btcutil.Amount,
|
|||||||
fee := ExpectedFee(path[i].cfg.FwrdingPolicy, prevAmount)
|
fee := ExpectedFee(path[i].cfg.FwrdingPolicy, prevAmount)
|
||||||
runningAmt += fee
|
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 {
|
if i == 0 {
|
||||||
amount = prevAmount
|
amount = prevAmount
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user