itest: manage context in CloseChannel and AssertChannelExists

This commit is contained in:
yyforyongyu
2021-08-20 01:35:02 +08:00
parent 3e26d77f91
commit 16403da91e
7 changed files with 39 additions and 55 deletions

View File

@@ -1163,10 +1163,14 @@ func (n *NetworkHarness) WaitForChannelOpen(
// passed channel point, initiated by the passed lnNode. If the passed context
// has a timeout, an error is returned if that timeout is reached before the
// channel close is pending.
func (n *NetworkHarness) CloseChannel(ctx context.Context,
lnNode *HarnessNode, cp *lnrpc.ChannelPoint,
func (n *NetworkHarness) CloseChannel(lnNode *HarnessNode,
cp *lnrpc.ChannelPoint,
force bool) (lnrpc.Lightning_CloseChannelClient, *chainhash.Hash, error) {
ctxb := context.Background()
ctx, cancel := context.WithTimeout(ctxb, ChannelCloseTimeout)
defer cancel()
// Create a channel outpoint that we can use to compare to channels
// from the ListChannelsResponse.
txidHash, err := getChanPointFundingTxid(cp)
@@ -1342,9 +1346,12 @@ func (n *NetworkHarness) WaitForChannelClose(
// assertions using channel's values. These functions are responsible for
// failing the test themselves if they do not pass.
// nolint: interfacer
func (n *NetworkHarness) AssertChannelExists(ctx context.Context,
node *HarnessNode, chanPoint *wire.OutPoint,
checks ...func(*lnrpc.Channel)) error {
func (n *NetworkHarness) AssertChannelExists(node *HarnessNode,
chanPoint *wire.OutPoint, checks ...func(*lnrpc.Channel)) error {
ctxb := context.Background()
ctx, cancel := context.WithTimeout(ctxb, ChannelCloseTimeout)
defer cancel()
req := &lnrpc.ListChannelsRequest{}