Skip to content

Commit 9427c78

Browse files
committed
itest: shuffle test cases to even out blocks mined in tranches
This commit shuffles all the test cases before running them so tests which require lots of blocks to be mined are less likely to be run in the same tranch. The other benefit is this approach provides a more efficient way to figure which tests are broken since all the differnet backends are running different tranches in their builds, we can identify more failed tests in one push.
1 parent b3acb5d commit 9427c78

2 files changed

Lines changed: 23 additions & 11 deletions

File tree

itest/list_on_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
package itest
44

5-
import "github.com/lightningnetwork/lnd/lntest"
5+
import (
6+
"math/rand"
7+
8+
"github.com/lightningnetwork/lnd/lntest"
9+
)
610

711
var allTestCases = []*lntest.TestCase{
812
{
@@ -631,3 +635,13 @@ var allTestCases = []*lntest.TestCase{
631635
TestFunc: testCoopCloseWithExternalDelivery,
632636
},
633637
}
638+
639+
func init() {
640+
// Shuffle the test cases so they are executed in a random order. This
641+
// is done to even out the blocks mined in each test tranche so they
642+
// can run faster.
643+
rand.Shuffle(len(allTestCases), func(i, j int) {
644+
allTestCases[i], allTestCases[j] =
645+
allTestCases[j], allTestCases[i]
646+
})
647+
}

itest/lnd_payment_test.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,15 @@ func testSendDirectPayment(ht *lntest.HarnessTest) {
141141
}
142142

143143
func testListPayments(ht *lntest.HarnessTest) {
144-
alice, bob := ht.Alice, ht.Bob
145-
146-
// Check that there are no payments before test.
147-
ht.AssertNumPayments(alice, 0)
144+
// Prepare test params.
145+
chanAmt := btcutil.Amount(100000)
146+
params := lntest.OpenChannelParams{Amt: chanAmt}
148147

149148
// Open a channel with 100k satoshis between Alice and Bob with Alice
150-
// being the sole funder of the channel.
151-
chanAmt := btcutil.Amount(100000)
152-
chanPoint := ht.OpenChannel(
153-
alice, bob, lntest.OpenChannelParams{Amt: chanAmt},
154-
)
149+
// being the sole funder of the channel. We use fresh nodes here so
150+
// they don't have old invoices or payments.
151+
chanPoints, nodes := createSimpleNetwork(ht, nil, 2, params)
152+
alice, bob := nodes[0], nodes[1]
155153

156154
// Now that the channel is open, create an invoice for Bob which
157155
// expects a payment of 1000 satoshis from Alice paid via a particular
@@ -320,7 +318,7 @@ func testListPayments(ht *lntest.HarnessTest) {
320318
time.Sleep(2 * time.Second)
321319

322320
// Close the channel.
323-
ht.CloseChannel(alice, chanPoint)
321+
ht.CloseChannel(alice, chanPoints[0])
324322
}
325323

326324
// testPaymentFollowingChannelOpen tests that the channel transition from

0 commit comments

Comments
 (0)