Merge pull request #3541 from halseth/itest-connection-refused-ignore

lnd_test: give peers more time to successfully attempt connection
This commit is contained in:
Johan T. Halseth 2019-10-07 10:23:52 +02:00 committed by GitHub
commit 1a5e39db88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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 {
switch { ctx, cancel := context.WithTimeout(ctx, 15*time.Second)
defer cancel()
// Request was successful, wait for both to display the err := n.connect(ctx, req, a)
// connection. switch {
case err == nil:
return errConnectionRequested
// If the two are already connected, we return early with no // Request was successful, wait for both to display the
// error. // connection.
case strings.Contains(err.Error(), "already connected to peer"): case err == nil:
return nil predErr = errConnectionRequested
return true
default: // If the two are already connected, we return early
return err // with no error.
case strings.Contains(
err.Error(), "already connected to peer",
):
predErr = nil
return true
default:
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
// Return any critical errors returned by either alice.
case aErr != nil && aErr != errConnectionRequested: case aErr != nil && aErr != errConnectionRequested:
// Return any critical errors returned by either alice.
return aErr return aErr
// Return any critical errors returned by either bob.
case bErr != nil && bErr != errConnectionRequested: case bErr != nil && bErr != errConnectionRequested:
// Return any critical errors returned by either bob.
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 {