Merge pull request #2230 from halseth/itests-tryconnect-peer

lntest/harness: retry ConnectPeer of chain backend still syncing
This commit is contained in:
Johan T. Halseth 2018-11-28 08:21:08 +01:00 committed by GitHub
commit 7e48b012e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -396,6 +396,28 @@ func (n *NetworkHarness) RegisterNode(node *HarnessNode) {
n.mtx.Unlock() n.mtx.Unlock()
} }
func (n *NetworkHarness) connect(ctx context.Context,
req *lnrpc.ConnectPeerRequest, a *HarnessNode) error {
syncTimeout := time.After(15 * time.Second)
tryconnect:
if _, err := a.ConnectPeer(ctx, req); err != nil {
// If the chain backend is still syncing, retry.
if strings.Contains(err.Error(), "still syncing") {
select {
case <-time.After(100 * time.Millisecond):
goto tryconnect
case <-syncTimeout:
return fmt.Errorf("chain backend did not " +
"finish syncing")
}
}
return err
}
return nil
}
// EnsureConnected will try to connect to two nodes, returning no error if they // EnsureConnected will try to connect to two nodes, returning no error if they
// are already connected. If the nodes were not connected previously, this will // are already connected. If the nodes were not connected previously, this will
// behave the same as ConnectNodes. If a pending connection request has already // behave the same as ConnectNodes. If a pending connection request has already
@ -422,7 +444,7 @@ func (n *NetworkHarness) EnsureConnected(ctx context.Context, a, b *HarnessNode)
} }
ctxt, _ = context.WithTimeout(ctx, 15*time.Second) ctxt, _ = context.WithTimeout(ctx, 15*time.Second)
_, err = a.ConnectPeer(ctxt, req) err = n.connect(ctxt, req, a)
switch { switch {
// Request was successful, wait for both to display the // Request was successful, wait for both to display the
@ -508,7 +530,8 @@ func (n *NetworkHarness) ConnectNodes(ctx context.Context, a, b *HarnessNode) er
Host: b.cfg.P2PAddr(), Host: b.cfg.P2PAddr(),
}, },
} }
if _, err := a.ConnectPeer(ctx, req); err != nil {
if err := n.connect(ctx, req, a); err != nil {
return err return err
} }