lnd_test: give peers more time to successfully attempt connection
We might hit a connection refused error in cases where the peer connects to us exactly as we try to connect to it. We retry the connection within a wait predicat, as it should be the case that the other peer establishes the connection, and the two peers actually connects.
This commit is contained in:
parent
867e972808
commit
a3a04992b4
@ -435,44 +435,61 @@ func (n *NetworkHarness) EnsureConnected(ctx context.Context, a, b *HarnessNode)
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
ctxt, _ = context.WithTimeout(ctx, 15*time.Second)
|
var predErr error
|
||||||
err = n.connect(ctxt, req, a)
|
err = wait.Predicate(func() bool {
|
||||||
|
ctx, cancel := context.WithTimeout(ctx, 15*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
err := n.connect(ctx, req, a)
|
||||||
switch {
|
switch {
|
||||||
|
|
||||||
// Request was successful, wait for both to display the
|
// Request was successful, wait for both to display the
|
||||||
// connection.
|
// connection.
|
||||||
case err == nil:
|
case err == nil:
|
||||||
return errConnectionRequested
|
predErr = errConnectionRequested
|
||||||
|
return true
|
||||||
|
|
||||||
// If the two are already connected, we return early with no
|
// If the two are already connected, we return early
|
||||||
// error.
|
// with no error.
|
||||||
case strings.Contains(err.Error(), "already connected to peer"):
|
case strings.Contains(
|
||||||
return nil
|
err.Error(), "already connected to peer",
|
||||||
|
):
|
||||||
|
predErr = nil
|
||||||
|
return true
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return err
|
predErr = err
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}, DefaultTimeout)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("connection not succeeded within 15 "+
|
||||||
|
"seconds: %v", predErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
return predErr
|
||||||
}
|
}
|
||||||
|
|
||||||
aErr := tryConnect(a, b)
|
aErr := tryConnect(a, b)
|
||||||
bErr := tryConnect(b, a)
|
bErr := tryConnect(b, a)
|
||||||
switch {
|
switch {
|
||||||
|
// If both reported already being connected to each other, we can exit
|
||||||
|
// early.
|
||||||
case aErr == nil && bErr == nil:
|
case aErr == nil && bErr == nil:
|
||||||
// If both reported already being connected to each other, we
|
|
||||||
// can exit early.
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
case aErr != nil && aErr != errConnectionRequested:
|
|
||||||
// Return any critical errors returned by either alice.
|
// Return any critical errors returned by either alice.
|
||||||
|
case aErr != nil && aErr != errConnectionRequested:
|
||||||
return aErr
|
return aErr
|
||||||
|
|
||||||
case bErr != nil && bErr != errConnectionRequested:
|
|
||||||
// Return any critical errors returned by either bob.
|
// Return any critical errors returned by either bob.
|
||||||
|
case bErr != nil && bErr != errConnectionRequested:
|
||||||
return bErr
|
return bErr
|
||||||
|
|
||||||
|
// Otherwise one or both requested a connection, so we wait for the
|
||||||
|
// peers lists to reflect the connection.
|
||||||
default:
|
default:
|
||||||
// Otherwise one or both requested a connection, so we wait for
|
|
||||||
// the peers lists to reflect the connection.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
findSelfInPeerList := func(a, b *HarnessNode) bool {
|
findSelfInPeerList := func(a, b *HarnessNode) bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user