Skip to content

Commit

Permalink
fix: add missing default service imports on reload
Browse files Browse the repository at this point in the history
Signed-off-by: Waldemar Quevedo <wally@nats.io>
  • Loading branch information
wallyqs committed Aug 2, 2023
1 parent 13cb62e commit 2b25246
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
52 changes: 47 additions & 5 deletions server/reload_test.go
Expand Up @@ -2603,6 +2603,23 @@ func TestConfigReloadAccountUsers(t *testing.T) {
t.Fatalf("Error on subscribe: %v", err)
}

// confirm subscriptions before and after reload.
var expectedSubs uint32 = 4
sAcc, _ := s.LookupAccount("synadia")
sAcc.mu.RLock()
n := sAcc.sl.Count()
sAcc.mu.RUnlock()
if n != expectedSubs {
t.Errorf("Synadia account should have %d sub, got %v", expectedSubs, n)
}
nAcc, _ := s.LookupAccount("nats.io")
nAcc.mu.RLock()
n = nAcc.sl.Count()
nAcc.mu.RUnlock()
if n != expectedSubs {
t.Errorf("Nats.io account should have %d sub, got %v", expectedSubs, n)
}

// Remove user from account and whole account
reloadUpdateConfig(t, s, conf, `
listen: "127.0.0.1:-1"
Expand Down Expand Up @@ -2678,8 +2695,8 @@ func TestConfigReloadAccountUsers(t *testing.T) {
n = sAcc.sl.Count()
barMatch := sAcc.sl.Match("bar")
sAcc.mu.RUnlock()
if n != 1 {
return fmt.Errorf("Synadia account should have 1 sub, got %v", n)
if n != expectedSubs {
return fmt.Errorf("Synadia account should have %d sub, got %v", expectedSubs, n)
}
if len(barMatch.psubs) != 1 {
return fmt.Errorf("Synadia account should have bar sub")
Expand All @@ -2690,8 +2707,8 @@ func TestConfigReloadAccountUsers(t *testing.T) {
n = nAcc.sl.Count()
batMatch := nAcc.sl.Match("bat")
nAcc.mu.RUnlock()
if n != 1 {
return fmt.Errorf("Nats.io account should have 1 sub, got %v", n)
if n != expectedSubs {
return fmt.Errorf("Nats.io account should have %d sub, got %v", expectedSubs, n)
}
if len(batMatch.psubs) != 1 {
return fmt.Errorf("Synadia account should have bar sub")
Expand Down Expand Up @@ -2719,15 +2736,40 @@ func TestConfigReloadAccountWithNoChanges(t *testing.T) {
}
}
`))
s, _ := RunServerWithConfig(conf)
s, opts := RunServerWithConfig(conf)
defer s.Shutdown()

ncA, err := nats.Connect(fmt.Sprintf("nats://a:@%s:%d", opts.Host, opts.Port))
if err != nil {
t.Fatalf("Error on connect: %v", err)
}
defer ncA.Close()

// Confirm service imports are ok.
resp, err := ncA.Request("$SYS.REQ.ACCOUNT.PING.CONNZ", nil, time.Second)
if err != nil {
t.Error(err)
}
if resp == nil || !strings.Contains(string(resp.Data), `"num_connections":1`) {
t.Fatal("unexpected data in connz response")
}

before := s.NumSubscriptions()
s.Reload()
after := s.NumSubscriptions()
if before != after {
t.Errorf("Number of subscriptions changed after reload: %d -> %d", before, after)
}

// Confirm this still works...
resp, err = ncA.Request("$SYS.REQ.ACCOUNT.PING.CONNZ", nil, time.Second)
if err != nil {
t.Fatal(err)
}
if resp == nil || !strings.Contains(string(resp.Data), `"num_connections":1`) {
t.Fatal("unexpected data in connz response")
}

before = s.NumSubscriptions()
s.Reload()
after = s.NumSubscriptions()
Expand Down
3 changes: 3 additions & 0 deletions server/server.go
Expand Up @@ -900,6 +900,9 @@ func (s *Server) configureAccounts(reloading bool) (map[string]struct{}, error)
c.processUnsub(sid)
}
acc.addAllServiceImportSubs()
s.mu.Unlock()
s.registerSystemImports(acc)
s.mu.Lock()
}

// Set the system account if it was configured.
Expand Down

0 comments on commit 2b25246

Please sign in to comment.