diff --git a/htlcswitch/link_test.go b/htlcswitch/link_test.go index fab177de..10e831cb 100644 --- a/htlcswitch/link_test.go +++ b/htlcswitch/link_test.go @@ -181,8 +181,8 @@ func TestChannelLinkBidirectionalOneHopPayments(t *testing.T) { // Send max available payment number in both sides, thereby testing // the property of channel link to cope with overflowing. - resultChan := make(chan *result) count := 2 * lnwallet.MaxHTLCNumber + resultChan := make(chan *result, count) for i := 0; i < count/2; i++ { go func(i int) { r := &result{ @@ -236,7 +236,7 @@ func TestChannelLinkBidirectionalOneHopPayments(t *testing.T) { } averageDelay += delay - case <-time.After(30 * time.Second): + case <-time.After(5 * time.Minute): t.Fatalf("timeout: (%v/%v)", i+1, count) } } diff --git a/htlcswitch/switch_test.go b/htlcswitch/switch_test.go index 2279d8ba..e55fbbee 100644 --- a/htlcswitch/switch_test.go +++ b/htlcswitch/switch_test.go @@ -181,7 +181,7 @@ func TestSwitchCancel(t *testing.T) { case <-aliceChannelLink.packets: break case <-time.After(time.Second): - t.Fatal("request was not propogated to channelPoint") + t.Fatal("request was not propagated to channelPoint") } if s.circuits.pending() != 0 { diff --git a/htlcswitch/test_utils.go b/htlcswitch/test_utils.go index 4d3ca67f..3be3b9fd 100644 --- a/htlcswitch/test_utils.go +++ b/htlcswitch/test_utils.go @@ -2,8 +2,8 @@ package htlcswitch import ( "bytes" + "crypto/rand" "crypto/sha256" - "math/rand" "testing" "time" @@ -65,6 +65,9 @@ func mockGetChanUpdateMessage() (*lnwire.ChannelUpdate, error) { func generateRandomBytes(n int) ([]byte, error) { b := make([]byte, n) + // TODO(roasbeef): should use counter in tests (atomic) rather than + // this + _, err := rand.Read(b[:]) // Note that Err == nil only if we read len(b) bytes. if err != nil { @@ -273,10 +276,6 @@ func getChanID(msg lnwire.Message) lnwire.ChannelID { func generatePayment(invoiceAmt, htlcAmt btcutil.Amount, timelock uint32, blob [lnwire.OnionPacketSize]byte) (*channeldb.Invoice, *lnwire.UpdateAddHTLC, error) { - // Initialize random seed with unix time in order to generate random - // preimage every time. - rand.Seed(time.Now().UTC().UnixNano()) - var preimage [sha256.Size]byte r, err := generateRandomBytes(sha256.Size) if err != nil { @@ -451,7 +450,7 @@ func (n *threeHopNetwork) makePayment(sendingPeer, receivingPeer Peer, select { case err := <-errChan: return invoice, err - case <-time.After(50 * time.Second): + case <-time.After(5 * time.Minute): return invoice, errors.New("htlc was not settled in time") } }