diff --git a/nats.go b/nats.go index ee7051227..40767a9ec 100644 --- a/nats.go +++ b/nats.go @@ -1874,9 +1874,9 @@ func (nc *Conn) processInfo(info string) error { // Remove from the temp map so that at the end we are left with only // new (or restarted) servers that need to be added to the pool. delete(tmp, curl) - // Keep the implicit one if we are currently connected to it. + // Keep servers that were set through Options, but also the one that + // we are currently connected to (even if it is a discovered server). if !srv.isImplicit || srv.url == nc.url { - delete(tmp, curl) continue } if !inInfo { diff --git a/test/cluster_test.go b/test/cluster_test.go index 3e08fb97f..e1ad77b61 100644 --- a/test/cluster_test.go +++ b/test/cluster_test.go @@ -652,7 +652,7 @@ func (d *checkPoolUpdatedDialer) Dial(network, address string) (net.Conn, error) } func TestServerPoolUpdatedWhenRouteGoesAway(t *testing.T) { - if err := serverVersionAtLeast(1, 0, 6); err != nil { + if err := serverVersionAtLeast(1, 0, 7); err != nil { t.Skipf(err.Error()) } s1Opts := test.DefaultTestOptions @@ -702,25 +702,27 @@ func TestServerPoolUpdatedWhenRouteGoesAway(t *testing.T) { // so try again on failure. var ( ds []string - timeout = time.Now().Add(3 * time.Second) + timeout = time.Now().Add(5 * time.Second) ) for time.Now().Before(timeout) { - startCheck: ds = nc.Servers() if len(ds) == len(expected) { m := make(map[string]struct{}, len(ds)) for _, url := range ds { m[url] = struct{}{} } + ok := true for _, url := range expected { if _, present := m[url]; !present { - time.Sleep(15 * time.Millisecond) - goto startCheck + ok = false + break } } - // we are good - return + if ok { + return + } } + time.Sleep(50 * time.Millisecond) } stackFatalf(t, "Expected %v, got %v", expected, ds) }