mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-21 22:11:41 +01:00
itest: require server being started when creating node
We now require the lnd to be fully started when creating a new node using newNode.
This commit is contained in:
parent
286ca35bf4
commit
c4913e6f4a
4 changed files with 47 additions and 0 deletions
|
@ -397,6 +397,7 @@ type HarnessNode struct {
|
|||
WalletKitClient walletrpc.WalletKitClient
|
||||
Watchtower watchtowerrpc.WatchtowerClient
|
||||
WatchtowerClient wtclientrpc.WatchtowerClientClient
|
||||
StateClient lnrpc.StateClient
|
||||
|
||||
// backupDbDir is the path where a database backup is stored, if any.
|
||||
backupDbDir string
|
||||
|
@ -940,6 +941,34 @@ func (hn *HarnessNode) Unlock(ctx context.Context,
|
|||
return hn.initClientWhenReady(DefaultTimeout)
|
||||
}
|
||||
|
||||
// waitTillServerStarted makes a subscription to the server's state change and
|
||||
// blocks until the server is in state ServerActive.
|
||||
func (hn *HarnessNode) waitTillServerStarted() error {
|
||||
ctxb := context.Background()
|
||||
ctxt, cancel := context.WithTimeout(ctxb, NodeStartTimeout)
|
||||
defer cancel()
|
||||
|
||||
client, err := hn.StateClient.SubscribeState(
|
||||
ctxt, &lnrpc.SubscribeStateRequest{},
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to subscribe to state: %w", err)
|
||||
}
|
||||
|
||||
for {
|
||||
resp, err := client.Recv()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to receive state "+
|
||||
"client stream: %w", err)
|
||||
}
|
||||
|
||||
if resp.State == lnrpc.WalletState_SERVER_ACTIVE {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// initLightningClient constructs the grpc LightningClient from the given client
|
||||
// connection and subscribes the harness node to graph topology updates.
|
||||
// This method also spawns a lightning network watcher for this node,
|
||||
|
@ -955,6 +984,12 @@ func (hn *HarnessNode) initLightningClient(conn *grpc.ClientConn) error {
|
|||
hn.Watchtower = watchtowerrpc.NewWatchtowerClient(conn)
|
||||
hn.WatchtowerClient = wtclientrpc.NewWatchtowerClientClient(conn)
|
||||
hn.SignerClient = signrpc.NewSignerClient(conn)
|
||||
hn.StateClient = lnrpc.NewStateClient(conn)
|
||||
|
||||
// Wait until the server is fully started.
|
||||
if err := hn.waitTillServerStarted(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Set the harness node's pubkey to what the node claims in GetInfo.
|
||||
// Since the RPC might not be immediately active, we wrap the call in a
|
||||
|
|
|
@ -24,4 +24,8 @@ const (
|
|||
// AsyncBenchmarkTimeout is the timeout used when running the async
|
||||
// payments benchmark.
|
||||
AsyncBenchmarkTimeout = 2 * time.Minute
|
||||
|
||||
// NodeStartTimeout is the timeout value when waiting for a node to
|
||||
// become fully started.
|
||||
NodeStartTimeout = time.Second * 60
|
||||
)
|
||||
|
|
|
@ -25,4 +25,8 @@ const (
|
|||
// payments benchmark. This timeout takes considerably longer on darwin
|
||||
// after go1.12 corrected its use of fsync.
|
||||
AsyncBenchmarkTimeout = time.Minute * 3
|
||||
|
||||
// NodeStartTimeout is the timeout value when waiting for a node to
|
||||
// become fully started.
|
||||
NodeStartTimeout = time.Second * 120
|
||||
)
|
||||
|
|
|
@ -24,4 +24,8 @@ const (
|
|||
// AsyncBenchmarkTimeout is the timeout used when running the async
|
||||
// payments benchmark.
|
||||
AsyncBenchmarkTimeout = 2 * time.Minute
|
||||
|
||||
// NodeStartTimeout is the timeout value when waiting for a node to
|
||||
// become fully started.
|
||||
NodeStartTimeout = time.Second * 60
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue