itest: wait for node to fully start up

This commit is contained in:
Oliver Gugger 2021-10-06 14:12:11 +02:00
parent e9c9ec2e84
commit 0fac6c400e
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
2 changed files with 25 additions and 2 deletions

View File

@ -403,7 +403,9 @@ func middlewareMandatoryTest(t *testing.T, node *lntest.HarnessNode,
// test case. So we need to do the wait and client setup manually here. // test case. So we need to do the wait and client setup manually here.
conn, err := node.ConnectRPC(true) conn, err := node.ConnectRPC(true)
require.NoError(t, err) require.NoError(t, err)
err = node.WaitUntilStarted(conn, defaultTimeout) err = node.WaitUntilStateReached(
conn, defaultTimeout, lnrpc.WalletState_RPC_ACTIVE,
)
require.NoError(t, err) require.NoError(t, err)
node.LightningClient = lnrpc.NewLightningClient(conn) node.LightningClient = lnrpc.NewLightningClient(conn)

View File

@ -887,6 +887,27 @@ func (hn *HarnessNode) start(lndBinary string, lndError chan<- error,
func (hn *HarnessNode) WaitUntilStarted(conn grpc.ClientConnInterface, func (hn *HarnessNode) WaitUntilStarted(conn grpc.ClientConnInterface,
timeout time.Duration) error { timeout time.Duration) error {
return hn.waitForState(conn, timeout, func(s lnrpc.WalletState) bool {
return s != lnrpc.WalletState_WAITING_TO_START
})
}
// WaitUntilStateReached waits until the given wallet state (or one of the
// states following it) has been reached.
func (hn *HarnessNode) WaitUntilStateReached(conn grpc.ClientConnInterface,
timeout time.Duration, desiredState lnrpc.WalletState) error {
return hn.waitForState(conn, timeout, func(s lnrpc.WalletState) bool {
return s >= desiredState
})
}
// waitForState waits until the current node state fulfills the given
// predicate.
func (hn *HarnessNode) waitForState(conn grpc.ClientConnInterface,
timeout time.Duration,
predicate func(state lnrpc.WalletState) bool) error {
stateClient := lnrpc.NewStateClient(conn) stateClient := lnrpc.NewStateClient(conn)
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
@ -908,7 +929,7 @@ func (hn *HarnessNode) WaitUntilStarted(conn grpc.ClientConnInterface,
return return
} }
if resp.State != lnrpc.WalletState_WAITING_TO_START { if predicate(resp.State) {
close(started) close(started)
return return
} }