Skip to content

Commit 7e48b01

Browse files
authored
Merge pull request #2230 from halseth/itests-tryconnect-peer
lntest/harness: retry ConnectPeer of chain backend still syncing
2 parents 0011bcd + b389d5f commit 7e48b01

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

lntest/harness.go

+25-2
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,28 @@ func (n *NetworkHarness) RegisterNode(node *HarnessNode) {
396396
n.mtx.Unlock()
397397
}
398398

399+
func (n *NetworkHarness) connect(ctx context.Context,
400+
req *lnrpc.ConnectPeerRequest, a *HarnessNode) error {
401+
402+
syncTimeout := time.After(15 * time.Second)
403+
tryconnect:
404+
if _, err := a.ConnectPeer(ctx, req); err != nil {
405+
// If the chain backend is still syncing, retry.
406+
if strings.Contains(err.Error(), "still syncing") {
407+
select {
408+
case <-time.After(100 * time.Millisecond):
409+
goto tryconnect
410+
case <-syncTimeout:
411+
return fmt.Errorf("chain backend did not " +
412+
"finish syncing")
413+
}
414+
}
415+
return err
416+
}
417+
418+
return nil
419+
}
420+
399421
// EnsureConnected will try to connect to two nodes, returning no error if they
400422
// are already connected. If the nodes were not connected previously, this will
401423
// 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)
422444
}
423445

424446
ctxt, _ = context.WithTimeout(ctx, 15*time.Second)
425-
_, err = a.ConnectPeer(ctxt, req)
447+
err = n.connect(ctxt, req, a)
426448
switch {
427449

428450
// Request was successful, wait for both to display the
@@ -508,7 +530,8 @@ func (n *NetworkHarness) ConnectNodes(ctx context.Context, a, b *HarnessNode) er
508530
Host: b.cfg.P2PAddr(),
509531
},
510532
}
511-
if _, err := a.ConnectPeer(ctx, req); err != nil {
533+
534+
if err := n.connect(ctx, req, a); err != nil {
512535
return err
513536
}
514537

0 commit comments

Comments
 (0)