lntest+lntest: inherit node's public states when restarting it

This commit changes how a node's state is created during startup. When
it already has states, only its internal states are reset since these
info are only useful for the finished test. The name `InitRPCClients` is
changed to `Initialize` to reflect the fact that it's more than
initializing RPC clients.
This commit is contained in:
yyforyongyu
2022-10-17 09:13:48 +08:00
parent 0b0c0f12ee
commit f3ad66b363
3 changed files with 34 additions and 9 deletions

View File

@@ -135,15 +135,24 @@ func NewHarnessNode(t *testing.T, cfg *BaseNodeConfig) (*HarnessNode, error) {
}, nil
}
// InitRPCClients initializes a list of RPC clients for the node.
func (hn *HarnessNode) InitRPCClients(c *grpc.ClientConn) {
// Initialize creates a list of new RPC clients using the passed connection,
// initializes the node's internal state and creates a topology watcher.
func (hn *HarnessNode) Initialize(c *grpc.ClientConn) {
hn.conn = c
// Init all the rpc clients.
hn.RPC = rpc.NewHarnessRPC(hn.runCtx, hn.T, c, hn.Name())
// Init the node's internal state.
hn.State = newState(hn.RPC)
// Init the node's state.
//
// If we already have a state, it means we are restarting the node and
// we will only reset its internal states. Otherwise we'll create a new
// state.
if hn.State != nil {
hn.State.resetEphermalStates(hn.RPC)
} else {
hn.State = newState(hn.RPC)
}
// Init the topology watcher.
hn.Watcher = newNodeWatcher(hn.RPC, hn.State)
@@ -436,8 +445,9 @@ func (hn *HarnessNode) Start(ctxt context.Context) error {
return err
}
// Init all the RPC clients.
hn.InitRPCClients(conn)
// Init the node by creating the RPC clients, initializing node's
// internal state and watcher.
hn.Initialize(conn)
// Wait till the server is starting.
if err := hn.WaitUntilStarted(); err != nil {
@@ -479,8 +489,9 @@ func (hn *HarnessNode) InitNode(macBytes []byte) error {
}
}
// Init all the RPC clients.
hn.InitRPCClients(conn)
// Init the node by creating the RPC clients, initializing node's
// internal state and watcher.
hn.Initialize(conn)
// Wait till the server is starting.
if err := hn.WaitUntilStarted(); err != nil {