lntest: replace hard coded timeouts

This commit replaces most of the hard coded 10, 15, 20 and 30 second
timeouts with the default timeout. This should allow darwin users to
successfully run the parallel itests locally as well.
This commit is contained in:
Oliver Gugger 2020-12-08 16:27:01 +01:00
parent dfb131f82f
commit cdcbc0376d
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
4 changed files with 74 additions and 74 deletions

@ -225,7 +225,7 @@ func (n *NetworkHarness) SetUp(testCase string, lndArgs []string) error {
balReq := &lnrpc.WalletBalanceRequest{}
balanceTicker := time.NewTicker(time.Millisecond * 200)
defer balanceTicker.Stop()
balanceTimeout := time.After(time.Second * 30)
balanceTimeout := time.After(DefaultTimeout)
out:
for {
select {
@ -290,7 +290,7 @@ func (n *NetworkHarness) NewNodeWithSeed(name string, extraArgs []string,
return nil, nil, nil, err
}
timeout := time.Duration(time.Second * 15)
timeout := time.Duration(DefaultTimeout)
ctxb := context.Background()
// Create a request to generate a new aezeed. The new seed will have the
@ -424,7 +424,7 @@ func (n *NetworkHarness) RegisterNode(node *HarnessNode) {
func (n *NetworkHarness) connect(ctx context.Context,
req *lnrpc.ConnectPeerRequest, a *HarnessNode) error {
syncTimeout := time.After(15 * time.Second)
syncTimeout := time.After(DefaultTimeout)
tryconnect:
if _, err := a.ConnectPeer(ctx, req); err != nil {
// If the chain backend is still syncing, retry.
@ -457,7 +457,7 @@ func (n *NetworkHarness) EnsureConnected(ctx context.Context, a, b *HarnessNode)
errConnectionRequested := errors.New("connection request in progress")
tryConnect := func(a, b *HarnessNode) error {
ctxt, _ := context.WithTimeout(ctx, 15*time.Second)
ctxt, _ := context.WithTimeout(ctx, DefaultTimeout)
bInfo, err := b.GetInfo(ctxt, &lnrpc.GetInfoRequest{})
if err != nil {
return err
@ -472,7 +472,7 @@ func (n *NetworkHarness) EnsureConnected(ctx context.Context, a, b *HarnessNode)
var predErr error
err = wait.Predicate(func() bool {
ctx, cancel := context.WithTimeout(ctx, 15*time.Second)
ctx, cancel := context.WithTimeout(ctx, DefaultTimeout)
defer cancel()
err := n.connect(ctx, req, a)
@ -530,7 +530,7 @@ func (n *NetworkHarness) EnsureConnected(ctx context.Context, a, b *HarnessNode)
// If node B is seen in the ListPeers response from node A,
// then we can exit early as the connection has been fully
// established.
ctxt, _ := context.WithTimeout(ctx, 15*time.Second)
ctxt, _ := context.WithTimeout(ctx, DefaultTimeout)
resp, err := b.ListPeers(ctxt, &lnrpc.ListPeersRequest{})
if err != nil {
return false
@ -547,7 +547,7 @@ func (n *NetworkHarness) EnsureConnected(ctx context.Context, a, b *HarnessNode)
err := wait.Predicate(func() bool {
return findSelfInPeerList(a, b) && findSelfInPeerList(b, a)
}, time.Second*15)
}, DefaultTimeout)
if err != nil {
return fmt.Errorf("peers not connected within 15 seconds")
}
@ -594,7 +594,7 @@ func (n *NetworkHarness) ConnectNodes(ctx context.Context, a, b *HarnessNode) er
}
return false
}, time.Second*15)
}, DefaultTimeout)
if err != nil {
return fmt.Errorf("peers not connected within 15 seconds")
}
@ -1038,7 +1038,7 @@ func (n *NetworkHarness) CloseChannel(ctx context.Context,
// We'll wait for *both* nodes to read the channel as active if we're
// performing a cooperative channel closure.
if !force {
timeout := time.Second * 15
timeout := DefaultTimeout
listReq := &lnrpc.ListChannelsRequest{}
// We define two helper functions, one two locate a particular
@ -1223,7 +1223,7 @@ func (n *NetworkHarness) AssertChannelExists(ctx context.Context,
}
return fmt.Errorf("channel %s not found", chanPoint)
}, 15*time.Second)
}, DefaultTimeout)
}
// DumpLogs reads the current logs generated by the passed node, and returns
@ -1355,7 +1355,7 @@ func (n *NetworkHarness) sendCoins(ctx context.Context, amt btcutil.Amount,
}
return nil
}, 15*time.Second)
}, DefaultTimeout)
if err != nil {
return fmt.Errorf("unconfirmed utxo was not found in "+
"ListUnspent: %v", err)

@ -520,7 +520,7 @@ func testChannelBackupUpdates(net *lntest.NetworkHarness, t *harnessTest) {
}
return nil
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("backup state invalid: %v", err)
}

@ -373,7 +373,7 @@ func assertChannelClosed(ctx context.Context, t *harnessTest,
}
return true
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("closing transaction not marked as fully closed")
}
@ -532,7 +532,7 @@ func assertNumOpenChannelsPending(ctxt context.Context, t *harnessTest,
}
return nil
}, 15*time.Second)
}, defaultTimeout)
if err != nil {
t.Fatalf(err.Error())
}
@ -703,7 +703,7 @@ func completePaymentRequests(ctx context.Context, client lnrpc.LightningClient,
}
return false
}, time.Second*15)
}, defaultTimeout)
if err != nil {
return err
}
@ -848,7 +848,7 @@ func testGetRecoveryInfo(net *lntest.NetworkHarness, t *harnessTest) {
}
return true
}, 15*time.Second)
}, defaultTimeout)
if err != nil {
t.Fatalf("expected recovery mode to be %v, got %v, "+
"expected recovery finished to be %v, got %v, "+
@ -952,7 +952,7 @@ func testOnchainFundRecovery(net *lntest.NetworkHarness, t *harnessTest) {
}
return true
}, 15*time.Second)
}, defaultTimeout)
if err != nil {
t.Fatalf("expected restored node to have %d satoshis, "+
"instead has %d satoshis, expected %d utxos "+
@ -1805,7 +1805,7 @@ out:
}
case err := <-subscription.errChan:
t.Fatalf("unable to recv graph update: %v", err)
case <-time.After(20 * time.Second):
case <-time.After(defaultTimeout):
t.Fatalf("did not receive channel update")
}
}
@ -2396,7 +2396,7 @@ func waitForNodeBlockHeight(ctx context.Context, node *lntest.HarnessNode,
height int32) error {
var predErr error
err := wait.Predicate(func() bool {
ctxt, _ := context.WithTimeout(ctx, 10*time.Second)
ctxt, _ := context.WithTimeout(ctx, defaultTimeout)
info, err := node.GetInfo(ctxt, &lnrpc.GetInfoRequest{})
if err != nil {
predErr = err
@ -2409,7 +2409,7 @@ func waitForNodeBlockHeight(ctx context.Context, node *lntest.HarnessNode,
return false
}
return true
}, 15*time.Second)
}, defaultTimeout)
if err != nil {
return predErr
}
@ -2445,7 +2445,7 @@ func assertMinerBlockHeightDelta(t *harnessTest,
return false
}
return true
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf(predErr.Error())
}
@ -2680,7 +2680,7 @@ func testOpenChannelAfterReorg(net *lntest.NetworkHarness, t *harnessTest) {
return false
}
return true
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf(predErr.Error())
}
@ -3619,7 +3619,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
return false
}
return true
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("htlc mismatch: %v", predErr)
}
@ -3821,7 +3821,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
}
return nil
}, 15*time.Second)
}, defaultTimeout)
if err != nil {
t.Fatalf(predErr.Error())
}
@ -3936,7 +3936,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
}
return nil
}, 15*time.Second)
}, defaultTimeout)
if err != nil {
t.Fatalf(err.Error())
}
@ -4069,7 +4069,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
}
return true
}, 15*time.Second)
}, defaultTimeout)
if err != nil {
t.Fatalf(predErr.Error())
}
@ -4143,7 +4143,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
}
return nil
}, 15*time.Second)
}, defaultTimeout)
if err != nil {
t.Fatalf(err.Error())
}
@ -4307,7 +4307,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
}
return true
}, 15*time.Second)
}, defaultTimeout)
if err != nil {
t.Fatalf(predErr.Error())
}
@ -4437,7 +4437,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
}
return true
}, 15*time.Second)
}, defaultTimeout)
if err != nil {
t.Fatalf(predErr.Error())
}
@ -4475,7 +4475,7 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
}
return true
}, 15*time.Second)
}, defaultTimeout)
if err != nil {
t.Fatalf(predErr.Error())
}
@ -5299,7 +5299,7 @@ func assertAmountPaid(t *harnessTest, channelName string,
// are in place
var timeover uint32
go func() {
<-time.After(time.Second * 20)
<-time.After(defaultTimeout)
atomic.StoreUint32(&timeover, 1)
}()
@ -6182,7 +6182,7 @@ func testUnannouncedChannels(net *lntest.NetworkHarness, t *harnessTest) {
return false
}
return true
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("%v", predErr)
}
@ -6534,7 +6534,7 @@ func testPrivateChannels(net *lntest.NetworkHarness, t *harnessTest) {
return false
}
return true
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("%v", predErr)
}
@ -6716,7 +6716,7 @@ func testInvoiceRoutingHints(net *lntest.NetworkHarness, t *harnessTest) {
return false
}
return true
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf(predErr.Error())
}
@ -7749,7 +7749,7 @@ func testFailingChannel(net *lntest.NetworkHarness, t *harnessTest) {
return false
}
return true
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("%v", predErr)
}
@ -7785,7 +7785,7 @@ func testFailingChannel(net *lntest.NetworkHarness, t *harnessTest) {
return false
}
return true
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("%v", predErr)
}
@ -7807,7 +7807,7 @@ func testFailingChannel(net *lntest.NetworkHarness, t *harnessTest) {
return false
}
return true
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("%v", predErr)
}
@ -7855,7 +7855,7 @@ func testFailingChannel(net *lntest.NetworkHarness, t *harnessTest) {
return false
}
return true
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("%v", predErr)
}
@ -7950,13 +7950,13 @@ func testGarbageCollectLinkNodes(net *lntest.NetworkHarness, t *harnessTest) {
err = wait.Predicate(func() bool {
return isConnected(net.Bob.PubKeyStr)
}, 15*time.Second)
}, defaultTimeout)
if err != nil {
t.Fatalf("alice did not reconnect to bob")
}
err = wait.Predicate(func() bool {
return isConnected(carol.PubKeyStr)
}, 15*time.Second)
}, defaultTimeout)
if err != nil {
t.Fatalf("alice did not reconnect to carol")
}
@ -7969,19 +7969,19 @@ func testGarbageCollectLinkNodes(net *lntest.NetworkHarness, t *harnessTest) {
err = wait.Predicate(func() bool {
return isConnected(net.Bob.PubKeyStr)
}, 15*time.Second)
}, defaultTimeout)
if err != nil {
t.Fatalf("alice did not reconnect to bob")
}
err = wait.Predicate(func() bool {
return isConnected(carol.PubKeyStr)
}, 15*time.Second)
}, defaultTimeout)
if err != nil {
t.Fatalf("alice did not reconnect to carol")
}
err = wait.Predicate(func() bool {
return isConnected(dave.PubKeyStr)
}, 15*time.Second)
}, defaultTimeout)
if err != nil {
t.Fatalf("alice did not reconnect to dave")
}
@ -8019,7 +8019,7 @@ func testGarbageCollectLinkNodes(net *lntest.NetworkHarness, t *harnessTest) {
}
err = wait.Predicate(func() bool {
return isConnected(dave.PubKeyStr)
}, 20*time.Second)
}, defaultTimeout)
if err != nil {
t.Fatalf("alice didn't reconnect to Dave")
}
@ -8091,7 +8091,7 @@ func testGarbageCollectLinkNodes(net *lntest.NetworkHarness, t *harnessTest) {
}
return true
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("channels not marked as fully resolved: %v", predErr)
}
@ -8223,7 +8223,7 @@ func testRevokedCloseRetribution(net *lntest.NetworkHarness, t *harnessTest) {
bobChan = bChan
return true
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("%v", predErr)
}
@ -8301,7 +8301,7 @@ func testRevokedCloseRetribution(net *lntest.NetworkHarness, t *harnessTest) {
}
return true
}, time.Second*10)
}, defaultTimeout)
if err != nil {
t.Fatalf("unable to close channel: %v", predErr)
}
@ -8555,7 +8555,7 @@ func testRevokedCloseRetributionZeroValueRemoteOutput(net *lntest.NetworkHarness
ctxt, carol, chanPoint, force,
)
return closeErr == nil
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("unable to close channel: %v", closeErr)
}
@ -8966,7 +8966,7 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness,
justiceTxid = txid
return true
}, time.Second*10)
}, defaultTimeout)
if err != nil && predErr == errNotFound {
// If Dave is unable to broadcast his justice tx on first
// attempt because of the second layer transactions, he will
@ -8986,7 +8986,7 @@ func testRevokedCloseRetributionRemoteHodl(net *lntest.NetworkHarness,
justiceTxid = txid
return true
}, time.Second*10)
}, defaultTimeout)
}
if err != nil {
t.Fatalf(predErr.Error())
@ -9480,7 +9480,7 @@ func testRevokedCloseRetributionAltruistWatchtowerCase(
}
return true
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("%v", predErr)
}
@ -9504,7 +9504,7 @@ func testRevokedCloseRetributionAltruistWatchtowerCase(
}
return true
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("%v", predErr)
}
@ -9543,7 +9543,7 @@ func assertNumPendingChannels(t *harnessTest, node *lntest.HarnessNode,
return false
}
return true
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("%v", predErr)
}
@ -9798,7 +9798,7 @@ func testDataLossProtection(net *lntest.NetworkHarness, t *harnessTest) {
nodeChan = bChan
return true
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("%v", predErr)
}
@ -10001,7 +10001,7 @@ func testDataLossProtection(net *lntest.NetworkHarness, t *harnessTest) {
}
return nil
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("%v", err)
}
@ -10037,7 +10037,7 @@ func assertNodeNumChannels(t *harnessTest, node *lntest.HarnessNode,
return true
}
if err := wait.Predicate(pred, time.Second*15); err != nil {
if err := wait.Predicate(pred, defaultTimeout); err != nil {
t.Fatalf("node has incorrect number of channels: %v", predErr)
}
}
@ -10583,7 +10583,7 @@ func testNodeAnnouncement(net *lntest.NetworkHarness, t *harnessTest) {
}
case err := <-graphSub.errChan:
t.Fatalf("unable to recv graph update: %v", err)
case <-time.After(20 * time.Second):
case <-time.After(defaultTimeout):
t.Fatalf("did not receive node ann update")
}
}
@ -11338,7 +11338,7 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) {
return false
}
return true
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("htlc mismatch: %v", predErr)
}
@ -11373,7 +11373,7 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) {
err = wait.Predicate(func() bool {
predErr = assertNumActiveHtlcs(nodes, numPayments)
return predErr == nil
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("htlc mismatch: %v", predErr)
}
@ -11397,7 +11397,7 @@ func testSwitchCircuitPersistence(net *lntest.NetworkHarness, t *harnessTest) {
predErr = assertNumActiveHtlcs(nodes, 0)
return predErr == nil
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("htlc mismatch: %v", predErr)
}
@ -11655,7 +11655,7 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
err = wait.Predicate(func() bool {
predErr = assertNumActiveHtlcs(nodes, numPayments)
return predErr == nil
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("htlc mismatch: %v", predErr)
}
@ -11678,7 +11678,7 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
err = wait.Invariant(func() bool {
predErr = assertNumActiveHtlcs(nodes, numPayments)
return predErr == nil
}, time.Second*2)
}, defaultTimeout)
if err != nil {
t.Fatalf("htlc change: %v", predErr)
}
@ -11702,7 +11702,7 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
err = wait.Predicate(func() bool {
predErr = assertNumActiveHtlcs(carolNode, 0)
return predErr == nil
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("htlc mismatch: %v", predErr)
}
@ -11721,7 +11721,7 @@ func testSwitchOfflineDelivery(net *lntest.NetworkHarness, t *harnessTest) {
return false
}
return true
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("htlc mismatch: %v", predErr)
}
@ -11982,7 +11982,7 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
}
return true
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("htlc mismatch: %v", predErr)
}
@ -12019,7 +12019,7 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
predErr = assertNumActiveHtlcsChanPoint(dave, carolFundPoint, 0)
return predErr == nil
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("htlc mismatch: %v", predErr)
}
@ -12049,7 +12049,7 @@ func testSwitchOfflineDeliveryPersistence(net *lntest.NetworkHarness, t *harness
return false
}
return true
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("htlc mismatch: %v", predErr)
}
@ -12316,7 +12316,7 @@ func testSwitchOfflineDeliveryOutgoingOffline(
return false
}
return true
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("htlc mismatch: %v", predErr)
}
@ -12344,7 +12344,7 @@ func testSwitchOfflineDeliveryOutgoingOffline(
predErr = assertNumActiveHtlcsChanPoint(dave, carolFundPoint, 0)
return predErr == nil
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("htlc mismatch: %v", predErr)
}
@ -12389,7 +12389,7 @@ func testSwitchOfflineDeliveryOutgoingOffline(
return false
}
return true
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("htlc mismatch: %v", predErr)
}
@ -13723,7 +13723,7 @@ func testHoldInvoicePersistence(net *lntest.NetworkHarness, t *harnessTest) {
}
return nil
}, time.Second*15)
}, defaultTimeout)
if err != nil {
t.Fatalf("predicate not satisfied: %v", err)
}

@ -660,7 +660,7 @@ func (hn *HarnessNode) initClientWhenReady() error {
if err := wait.NoError(func() error {
conn, connErr = hn.ConnectRPC(true)
return connErr
}, 5*time.Second); err != nil {
}, DefaultTimeout); err != nil {
return err
}
@ -1005,7 +1005,7 @@ func (hn *HarnessNode) stop() error {
// Wait for lnd process and other goroutines to exit.
select {
case <-hn.processExit:
case <-time.After(60 * time.Second):
case <-time.After(DefaultTimeout * 2):
return fmt.Errorf("process did not exit")
}
@ -1357,7 +1357,7 @@ func (hn *HarnessNode) WaitForBalance(expectedBalance btcutil.Amount, confirmed
return btcutil.Amount(balance.UnconfirmedBalance) == expectedBalance
}
err := wait.Predicate(doesBalanceMatch, 30*time.Second)
err := wait.Predicate(doesBalanceMatch, DefaultTimeout)
if err != nil {
return fmt.Errorf("balances not synced after deadline: "+
"expected %v, only have %v", expectedBalance, lastBalance)