Use specific boolean for a leaf test instead of using leafNodeEnabled

A test TestJetStreamClusterLeafNodeSPOFMigrateLeaders was added at
some point that needed the remotes to stop (re)connecting. It made
use of existing leafNodeEnabled that was used for GW/Leaf interest
propagation races to disable the reconnect, but that may not be
the best approach since it could affect users embedding servers
and adding leafnodes "dynamically".

So this PR introduced a specific boolean specific for that test.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
This commit is contained in:
Ivan Kozlovic
2022-08-04 10:00:11 -06:00
parent 5df91797d6
commit d84d9f8288
3 changed files with 9 additions and 7 deletions

View File

@@ -951,7 +951,7 @@ func (s *Server) closeAndDisableLeafnodes() {
leafs = append(leafs, ln)
}
// Disable leafnodes for now.
s.leafNodeEnabled = false
s.leafDisableConnect = true
s.mu.Unlock()
for _, ln := range leafs {

View File

@@ -495,12 +495,13 @@ func (s *Server) connectToRemoteLeafNode(remote *leafNodeCfg, firstConnect bool)
if url != rURL.Host {
ipStr = fmt.Sprintf(" (%s)", url)
}
if s.isLeafNodeEnabled() {
s.Debugf("Trying to connect as leafnode to remote server on %q%s", rURL.Host, ipStr)
conn, err = natsDialTimeout("tcp", url, dialTimeout)
} else {
// Some test may want to disable remotes from connecting
if s.isLeafConnectDisabled() {
s.Debugf("Will not attempt to connect to remote server on %q%s, leafnodes currently disabled", rURL.Host, ipStr)
err = ErrLeafNodeDisabled
} else {
s.Debugf("Trying to connect as leafnode to remote server on %q%s", rURL.Host, ipStr)
conn, err = natsDialTimeout("tcp", url, dialTimeout)
}
}
if err != nil {
@@ -569,10 +570,10 @@ func (s *Server) checkJetStreamMigrate(remote *leafNodeCfg) {
}
// Helper for checking.
func (s *Server) isLeafNodeEnabled() bool {
func (s *Server) isLeafConnectDisabled() bool {
s.mu.RLock()
defer s.mu.RUnlock()
return s.leafNodeEnabled
return s.leafDisableConnect
}
// Save off the tlsName for when we use TLS and mix hostnames and IPs. IPs usually

View File

@@ -164,6 +164,7 @@ type Server struct {
leafRemoteCfgs []*leafNodeCfg
leafRemoteAccounts sync.Map
leafNodeEnabled bool
leafDisableConnect bool // Used in test only
quitCh chan struct{}
startupComplete chan struct{}