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 committed 2023-01-18 10:53:58 +08:00
1 parent 0b0c0f12ee
commit f3ad66b363
3 files changed
+34 -9

No files matched your search

+19 -8
View File
@@ -135,15 +135,24 @@ func NewHarnessNode(t *testing.T, cfg *BaseNodeConfig) (*HarnessNode, error) {
}, nil }, nil
} }
// InitRPCClients initializes a list of RPC clients for the node. // Initialize creates a list of new RPC clients using the passed connection,
func (hn *HarnessNode) InitRPCClients(c *grpc.ClientConn) { // initializes the node's internal state and creates a topology watcher.
func (hn *HarnessNode) Initialize(c *grpc.ClientConn) {
hn.conn = c hn.conn = c
// Init all the rpc clients. // Init all the rpc clients.
hn.RPC = rpc.NewHarnessRPC(hn.runCtx, hn.T, c, hn.Name()) hn.RPC = rpc.NewHarnessRPC(hn.runCtx, hn.T, c, hn.Name())
// Init the node's internal state. // Init the node's state.
hn.State = newState(hn.RPC) //
// 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. // Init the topology watcher.
hn.Watcher = newNodeWatcher(hn.RPC, hn.State) hn.Watcher = newNodeWatcher(hn.RPC, hn.State)
@@ -436,8 +445,9 @@ func (hn *HarnessNode) Start(ctxt context.Context) error {
return err return err
} }
// Init all the RPC clients. // Init the node by creating the RPC clients, initializing node's
hn.InitRPCClients(conn) // internal state and watcher.
hn.Initialize(conn)
// Wait till the server is starting. // Wait till the server is starting.
if err := hn.WaitUntilStarted(); err != nil { if err := hn.WaitUntilStarted(); err != nil {
@@ -479,8 +489,9 @@ func (hn *HarnessNode) InitNode(macBytes []byte) error {
} }
} }
// Init all the RPC clients. // Init the node by creating the RPC clients, initializing node's
hn.InitRPCClients(conn) // internal state and watcher.
hn.Initialize(conn)
// Wait till the server is starting. // Wait till the server is starting.
if err := hn.WaitUntilStarted(); err != nil { if err := hn.WaitUntilStarted(); err != nil {
+14
View File
@@ -344,3 +344,17 @@ func (s *State) String() string {
return fmt.Sprintf("\n%s", stateBytes) return fmt.Sprintf("\n%s", stateBytes)
} }
// resetEphermalStates resets the current state with a new HarnessRPC and empty
// private fields which are used to track state only valid for the last test.
func (s *State) resetEphermalStates(rpc *rpc.HarnessRPC) {
s.rpc = rpc
// Reset ephermal states which are used to record info from finished
// tests.
s.openChans = &SyncMap[wire.OutPoint, []*OpenChannelUpdate]{}
s.closedChans = &SyncMap[wire.OutPoint, *lnrpc.ClosedChannelUpdate]{}
s.numChanUpdates = &SyncMap[wire.OutPoint, int]{}
s.nodeUpdates = &SyncMap[string, []*lnrpc.NodeUpdate]{}
s.policyUpdates = &SyncMap[wire.OutPoint, PolicyUpdate]{}
}
@@ -560,7 +560,7 @@ func middlewareMandatoryTest(ht *lntemp.HarnessTest, node *node.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() conn, err := node.ConnectRPC()
require.NoError(ht, err) require.NoError(ht, err)
node.InitRPCClients(conn) node.Initialize(conn)
err = node.WaitUntilServerActive() err = node.WaitUntilServerActive()
require.NoError(ht, err) require.NoError(ht, err)