From c3f84b1a47a48cf96ddeab790df793e0a094350e Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 21 Dec 2017 11:35:23 +0100 Subject: [PATCH] lntest: re-write AssertChannelExists to use WaitPredicate internally MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Recent changes to the funding manger’s state machine have resulted in some additional database calls during the funding process. This has slowed down the tests by a few ms here and there. Recent integration test runs have begun to fail due to AssertChannelExists returning an error as the channel hasn’t fully propagated yet. In order to remedy this, we’ll now use WaitPredicate to poll repeatedly to ensure. This should serve to reduce flakes encountered within the integration tests. --- lntest/harness.go | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/lntest/harness.go b/lntest/harness.go index ab2537e7d..b8d5d88a4 100644 --- a/lntest/harness.go +++ b/lntest/harness.go @@ -766,13 +766,31 @@ func (n *NetworkHarness) AssertChannelExists(ctx context.Context, node *HarnessNode, chanPoint *wire.OutPoint) error { req := &lnrpc.ListChannelsRequest{} - resp, err := node.ListChannels(ctx, req) - if err != nil { - return fmt.Errorf("unable fetch node's channels: %v", err) + + var predErr error + pred := func() bool { + resp, err := node.ListChannels(ctx, req) + if err != nil { + predErr = fmt.Errorf("unable fetch node's channels: %v", err) + return false + } + + for _, channel := range resp.Channels { + if channel.ChannelPoint == chanPoint.String() { + return true + } + + } + return false } - for _, channel := range resp.Channels { - if channel.ChannelPoint == chanPoint.String() { + if err := WaitPredicate(pred, time.Second*15); err != nil { + return fmt.Errorf("channel not found: %v", predErr) + } + + return nil +} + // WaitPredicate is a helper test function that will wait for a timeout period // of time until the passed predicate returns true. This function is helpful as // timing doesn't always line up well when running integration tests with