From 106fbeae859b471f11eb35c2792eb9d2db59c6b4 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Fri, 12 Aug 2022 11:19:18 +0800 Subject: [PATCH] multi: move timeouts into package `wait` This commit moves the definition of timeout values into package `wait`, preparing the incoming merging of `lntemp` and `lntest`. --- itest/lnd_payment_test.go | 5 ++--- itest/test_harness.go | 6 +++--- lntemp/harness.go | 2 +- lntemp/harness_miner.go | 6 +++--- lntemp/node/config.go | 3 ++- lntemp/node/harness_node.go | 16 ++++++++-------- lntemp/node/watcher.go | 15 +++++---------- lntemp/rpc/harness_rpc.go | 5 ++--- lntest/harness_node.go | 7 ++++++- lntest/{ => wait}/timeouts.go | 2 +- lntest/{ => wait}/timeouts_darwin.go | 2 +- lntest/{ => wait}/timeouts_remote_db.go | 2 +- 12 files changed, 35 insertions(+), 36 deletions(-) rename lntest/{ => wait}/timeouts.go (98%) rename lntest/{ => wait}/timeouts_darwin.go (98%) rename lntest/{ => wait}/timeouts_remote_db.go (98%) diff --git a/itest/lnd_payment_test.go b/itest/lnd_payment_test.go index e9005e6e9..754c7e937 100644 --- a/itest/lnd_payment_test.go +++ b/itest/lnd_payment_test.go @@ -12,7 +12,6 @@ import ( "github.com/lightningnetwork/lnd/lnrpc/routerrpc" "github.com/lightningnetwork/lnd/lntemp" "github.com/lightningnetwork/lnd/lntemp/node" - "github.com/lightningnetwork/lnd/lntest" "github.com/lightningnetwork/lnd/lntest/wait" "github.com/stretchr/testify/require" ) @@ -272,7 +271,7 @@ func runAsyncPayments(ht *lntemp.HarnessTest, alice, bob *node.HarnessNode) { settled := make(chan struct{}) defer close(settled) - timeout := lntest.AsyncBenchmarkTimeout * 2 + timeout := wait.AsyncBenchmarkTimeout * 2 for i := 0; i < numInvoices; i++ { payReq := bobPayReqs[i] go func() { @@ -376,7 +375,7 @@ func testBidirectionalAsyncPayments(ht *lntemp.HarnessTest) { settled := make(chan struct{}) defer close(settled) - timeout := lntest.AsyncBenchmarkTimeout * 4 + timeout := wait.AsyncBenchmarkTimeout * 4 send := func(node *node.HarnessNode, payReq string) { req := &routerrpc.SendPaymentRequest{ PaymentRequest: payReq, diff --git a/itest/test_harness.go b/itest/test_harness.go index a5450026f..88f11ba08 100644 --- a/itest/test_harness.go +++ b/itest/test_harness.go @@ -38,9 +38,9 @@ var ( const ( testFeeBase = 1e+6 defaultCSV = lntest.DefaultCSV - defaultTimeout = lntest.DefaultTimeout - minerMempoolTimeout = lntest.MinerMempoolTimeout - channelCloseTimeout = lntest.ChannelCloseTimeout + defaultTimeout = wait.DefaultTimeout + minerMempoolTimeout = wait.MinerMempoolTimeout + channelCloseTimeout = wait.ChannelCloseTimeout itestLndBinary = "../../lnd-itest" anchorSize = 330 noFeeLimitMsat = math.MaxInt64 diff --git a/lntemp/harness.go b/lntemp/harness.go index 781a5ccf3..cc11ec9ae 100644 --- a/lntemp/harness.go +++ b/lntemp/harness.go @@ -1686,7 +1686,7 @@ func (h *HarnessTest) OpenMultiChannelsAsync( case cp := <-r.result: channelPoints = append(channelPoints, cp) - case <-time.After(lntest.ChannelOpenTimeout): + case <-time.After(wait.ChannelOpenTimeout): require.Failf(h, "timeout", "wait channel point "+ "timeout for channel %s=>%s", r.Local.Name(), r.Remote.Name()) diff --git a/lntemp/harness_miner.go b/lntemp/harness_miner.go index 9c9b758f2..9568a2c86 100644 --- a/lntemp/harness_miner.go +++ b/lntemp/harness_miner.go @@ -198,7 +198,7 @@ func (h *HarnessMiner) AssertNumTxsInMempool(n int) []*chainhash.Hash { return fmt.Errorf("want %v, got %v in mempool: %v", n, len(mem), mem) - }, lntest.MinerMempoolTimeout) + }, wait.MinerMempoolTimeout) require.NoError(h, err, "assert tx in mempool timeout") return mem @@ -286,7 +286,7 @@ func (h *HarnessMiner) AssertTxInMempool(txid *chainhash.Hash) *wire.MsgTx { return fmt.Errorf("txid %v not found in mempool: %v", txid, mempool) - }, lntest.MinerMempoolTimeout) + }, wait.MinerMempoolTimeout) require.NoError(h, err, "timeout checking mempool") return msgTx @@ -377,7 +377,7 @@ func (h *HarnessMiner) AssertOutpointInMempool(op wire.OutPoint) *wire.MsgTx { } return fmt.Errorf("outpoint %v not found in mempool", op) - }, lntest.MinerMempoolTimeout) + }, wait.MinerMempoolTimeout) require.NoError(h, err, "timeout checking mempool") diff --git a/lntemp/node/config.go b/lntemp/node/config.go index 00b183354..ef00d1bfa 100644 --- a/lntemp/node/config.go +++ b/lntemp/node/config.go @@ -9,6 +9,7 @@ import ( "github.com/lightningnetwork/lnd/chanbackup" "github.com/lightningnetwork/lnd/kvdb/etcd" "github.com/lightningnetwork/lnd/lntest" + "github.com/lightningnetwork/lnd/lntest/wait" ) const ( @@ -228,7 +229,7 @@ func (cfg *BaseNodeConfig) GenArgs() []string { case lntest.BackendSqlite: args = append(args, "--db.backend=sqlite") args = append(args, fmt.Sprintf("--db.sqlite.busytimeout=%v", - lntest.SqliteBusyTimeout)) + wait.SqliteBusyTimeout)) } if cfg.FeeURL != "" { diff --git a/lntemp/node/harness_node.go b/lntemp/node/harness_node.go index 069d23ec8..c86e30af8 100644 --- a/lntemp/node/harness_node.go +++ b/lntemp/node/harness_node.go @@ -324,7 +324,7 @@ func (hn *HarnessNode) ConnectRPCWithMacaroon(mac *macaroon.Macaroon) ( hn.Cfg.TLSCertPath, "", ) return err - }, DefaultTimeout) + }, wait.DefaultTimeout) if err != nil { return nil, fmt.Errorf("error reading TLS cert: %v", err) } @@ -334,7 +334,7 @@ func (hn *HarnessNode) ConnectRPCWithMacaroon(mac *macaroon.Macaroon) ( grpc.WithTransportCredentials(tlsCreds), } - ctx, cancel := context.WithTimeout(hn.runCtx, DefaultTimeout) + ctx, cancel := context.WithTimeout(hn.runCtx, wait.DefaultTimeout) defer cancel() if mac == nil { @@ -354,7 +354,7 @@ func (hn *HarnessNode) ConnectRPCWithMacaroon(mac *macaroon.Macaroon) ( func (hn *HarnessNode) ConnectRPC() (*grpc.ClientConn, error) { // If we should use a macaroon, always take the admin macaroon as a // default. - mac, err := hn.ReadMacaroon(hn.Cfg.AdminMacPath, DefaultTimeout) + mac, err := hn.ReadMacaroon(hn.Cfg.AdminMacPath, wait.DefaultTimeout) if err != nil { return nil, err } @@ -540,7 +540,7 @@ func (hn *HarnessNode) waitTillServerState( for { select { - case <-time.After(lntest.NodeStartTimeout): + case <-time.After(wait.NodeStartTimeout): return fmt.Errorf("timeout waiting for server state") case err := <-errChan: return fmt.Errorf("receive server state err: %v", err) @@ -581,7 +581,7 @@ func (hn *HarnessNode) initLightningClient() error { "got err: %v", err) } - case <-time.After(DefaultTimeout): + case <-time.After(wait.DefaultTimeout): return fmt.Errorf("timeout creating topology client stream") } @@ -652,7 +652,7 @@ func (hn *HarnessNode) waitForProcessExit() { hn.printErrf("wait process exit got err: %v", err) break - case <-time.After(DefaultTimeout * 2): + case <-time.After(wait.DefaultTimeout * 2): hn.printErrf("timeout waiting for process to exit") } @@ -705,7 +705,7 @@ func (hn *HarnessNode) Stop() error { default: return nil } - }, DefaultTimeout) + }, wait.DefaultTimeout) if err != nil { return err } @@ -720,7 +720,7 @@ func (hn *HarnessNode) Stop() error { // If the goroutines fail to finish before timeout, we'll print // the error to console and continue. select { - case <-time.After(DefaultTimeout): + case <-time.After(wait.DefaultTimeout): hn.printErrf("timeout on wait group") case <-done: } diff --git a/lntemp/node/watcher.go b/lntemp/node/watcher.go index af0bf66cb..dd36e3202 100644 --- a/lntemp/node/watcher.go +++ b/lntemp/node/watcher.go @@ -12,7 +12,6 @@ import ( "github.com/btcsuite/btcd/wire" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lntemp/rpc" - "github.com/lightningnetwork/lnd/lntest" "github.com/lightningnetwork/lnd/lntest/wait" "github.com/lightningnetwork/lnd/lnutils" ) @@ -31,9 +30,6 @@ const ( // watchPolicyUpdate specifies that this is a request to watch a policy // update event. watchPolicyUpdate - - // TODO(yy): remove once temp tests is finished. - DefaultTimeout = lntest.DefaultTimeout ) // chanWatchRequest is a request to the lightningNetworkWatcher to be notified @@ -123,7 +119,7 @@ func (nw *nodeWatcher) WaitForNumChannelUpdates(op wire.OutPoint, "want %d, got %d", expected, num) } - return wait.NoError(checkNumUpdates, DefaultTimeout) + return wait.NoError(checkNumUpdates, wait.DefaultTimeout) } // WaitForNumNodeUpdates will block until a given number of node updates has @@ -142,8 +138,7 @@ func (nw *nodeWatcher) WaitForNumNodeUpdates(pubkey string, return fmt.Errorf("timeout waiting for num node updates, "+ "want %d, got %d", expected, num) } - - err := wait.NoError(checkNumUpdates, DefaultTimeout) + err := wait.NoError(checkNumUpdates, wait.DefaultTimeout) return updates, err } @@ -161,7 +156,7 @@ func (nw *nodeWatcher) WaitForChannelOpen(chanPoint *lnrpc.ChannelPoint) error { chanWatchType: watchOpenChannel, } - timer := time.After(DefaultTimeout) + timer := time.After(wait.DefaultTimeout) select { case <-eventChan: return nil @@ -192,7 +187,7 @@ func (nw *nodeWatcher) WaitForChannelClose( chanWatchType: watchCloseChannel, } - timer := time.After(DefaultTimeout) + timer := time.After(wait.DefaultTimeout) select { case <-eventChan: closedChan, ok := nw.state.closedChans.Load(op) @@ -218,7 +213,7 @@ func (nw *nodeWatcher) WaitForChannelPolicyUpdate( op := nw.rpc.MakeOutpoint(chanPoint) ticker := time.NewTicker(wait.PollInterval) - timer := time.After(DefaultTimeout) + timer := time.After(wait.DefaultTimeout) defer ticker.Stop() eventChan := make(chan struct{}) diff --git a/lntemp/rpc/harness_rpc.go b/lntemp/rpc/harness_rpc.go index 549d2dc76..9de698536 100644 --- a/lntemp/rpc/harness_rpc.go +++ b/lntemp/rpc/harness_rpc.go @@ -15,14 +15,13 @@ import ( "github.com/lightningnetwork/lnd/lnrpc/walletrpc" "github.com/lightningnetwork/lnd/lnrpc/watchtowerrpc" "github.com/lightningnetwork/lnd/lnrpc/wtclientrpc" - "github.com/lightningnetwork/lnd/lntest" + "github.com/lightningnetwork/lnd/lntest/wait" "github.com/stretchr/testify/require" "google.golang.org/grpc" ) const ( - // TODO(yy): remove once temp tests is finished. - DefaultTimeout = lntest.DefaultTimeout + DefaultTimeout = wait.DefaultTimeout ) // HarnessRPC wraps all lnd's RPC clients into a single struct for easier diff --git a/lntest/harness_node.go b/lntest/harness_node.go index db9ad7fab..26dc90498 100644 --- a/lntest/harness_node.go +++ b/lntest/harness_node.go @@ -58,6 +58,11 @@ const ( // will wait between attempting to flush a batch of modifications to // disk(db.batch-commit-interval). commitInterval = 10 * time.Millisecond + + DefaultTimeout = wait.DefaultTimeout + NodeStartTimeout = wait.NodeStartTimeout + ChannelOpenTimeout = wait.ChannelOpenTimeout + ChannelCloseTimeout = wait.ChannelCloseTimeout ) var ( @@ -282,7 +287,7 @@ func (cfg *BaseNodeConfig) GenArgs() []string { case BackendSqlite: args = append(args, "--db.backend=sqlite") args = append(args, fmt.Sprintf("--db.sqlite.busytimeout=%v", - SqliteBusyTimeout)) + wait.SqliteBusyTimeout)) } if cfg.FeeURL != "" { diff --git a/lntest/timeouts.go b/lntest/wait/timeouts.go similarity index 98% rename from lntest/timeouts.go rename to lntest/wait/timeouts.go index 34418d4b5..507edd87a 100644 --- a/lntest/timeouts.go +++ b/lntest/wait/timeouts.go @@ -1,7 +1,7 @@ //go:build !darwin && !kvdb_etcd && !kvdb_postgres // +build !darwin,!kvdb_etcd,!kvdb_postgres -package lntest +package wait import "time" diff --git a/lntest/timeouts_darwin.go b/lntest/wait/timeouts_darwin.go similarity index 98% rename from lntest/timeouts_darwin.go rename to lntest/wait/timeouts_darwin.go index 3d61e3b0a..f08cd215a 100644 --- a/lntest/timeouts_darwin.go +++ b/lntest/wait/timeouts_darwin.go @@ -1,7 +1,7 @@ //go:build darwin && !kvdb_etcd && !kvdb_postgres // +build darwin,!kvdb_etcd,!kvdb_postgres -package lntest +package wait import "time" diff --git a/lntest/timeouts_remote_db.go b/lntest/wait/timeouts_remote_db.go similarity index 98% rename from lntest/timeouts_remote_db.go rename to lntest/wait/timeouts_remote_db.go index 300a8cf1c..c6805118b 100644 --- a/lntest/timeouts_remote_db.go +++ b/lntest/wait/timeouts_remote_db.go @@ -1,7 +1,7 @@ //go:build kvdb_etcd || kvdb_postgres // +build kvdb_etcd kvdb_postgres -package lntest +package wait import "time"