itest: manage context timeout inside network harness

This is the last commit to refactor the context management such that all
the timeout are managed inside the network harness.
This commit is contained in:
yyforyongyu committed 2021-08-24 12:28:35 +08:00
1 parent d9e9238b0c
commit 5a94919b7e
13 files changed
+49 -64

No files matched your search

+17 -6
View File
@@ -723,7 +723,11 @@ func (n *NetworkHarness) ConnectNodes(t *testing.T, a, b *HarnessNode) {
// DisconnectNodes disconnects node a from node b by sending RPC message
// from a node to b node
func (n *NetworkHarness) DisconnectNodes(ctx context.Context, a, b *HarnessNode) error {
func (n *NetworkHarness) DisconnectNodes(a, b *HarnessNode) error {
ctxb := context.Background()
ctx, cancel := context.WithTimeout(ctxb, DefaultTimeout)
defer cancel()
bobInfo, err := b.GetInfo(ctx, &lnrpc.GetInfoRequest{})
if err != nil {
return err
@@ -988,9 +992,12 @@ type OpenChannelParams struct {
// if the timeout is reached before the channel pending notification is
// received, an error is returned. The confirmed boolean determines whether we
// should fund the channel with confirmed outputs or not.
func (n *NetworkHarness) OpenChannel(ctx context.Context,
srcNode, destNode *HarnessNode, p OpenChannelParams) (
lnrpc.Lightning_OpenChannelClient, error) {
func (n *NetworkHarness) OpenChannel(srcNode, destNode *HarnessNode,
p OpenChannelParams) (lnrpc.Lightning_OpenChannelClient, error) {
ctxb := context.Background()
ctx, cancel := context.WithTimeout(ctxb, ChannelOpenTimeout)
defer cancel()
// Wait until srcNode and destNode have the latest chain synced.
// Otherwise, we may run into a check within the funding manager that
@@ -1062,10 +1069,14 @@ func (n *NetworkHarness) OpenChannel(ctx context.Context,
// passed channel funding parameters. If the passed context has a timeout, then
// if the timeout is reached before the channel pending notification is
// received, an error is returned.
func (n *NetworkHarness) OpenPendingChannel(ctx context.Context,
srcNode, destNode *HarnessNode, amt btcutil.Amount,
func (n *NetworkHarness) OpenPendingChannel(srcNode, destNode *HarnessNode,
amt btcutil.Amount,
pushAmt btcutil.Amount) (*lnrpc.PendingUpdate, error) {
ctxb := context.Background()
ctx, cancel := context.WithTimeout(ctxb, ChannelOpenTimeout)
defer cancel()
// Wait until srcNode and destNode have blockchain synced
if err := srcNode.WaitForBlockchainSync(ctx); err != nil {
return nil, fmt.Errorf("unable to sync srcNode chain: %v", err)