Skip to content

Commit

Permalink
Also make sure account works after reload
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Collison <derek@nats.io>
  • Loading branch information
derekcollison committed Dec 1, 2020
1 parent 7e27042 commit 4e6d600
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
6 changes: 5 additions & 1 deletion server/reload.go
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,11 @@ func (s *Server) reloadAuthorization() {

// We will double check all JetStream configs on a reload.
if checkJetStream {
s.configAllJetStreamAccounts()
if s.globalAccountOnly() {
s.GlobalAccount().EnableJetStream(nil)
} else {
s.configAllJetStreamAccounts()
}
}

if res := s.AccountResolver(); res != nil {
Expand Down
39 changes: 39 additions & 0 deletions test/jetstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10226,3 +10226,42 @@ func TestJetStreamServerReload(t *testing.T) {
checkJSAccount()
sendStreamMsg(t, nc, "22", "MSG: 22")
}

func TestJetStreamConfigReloadWithGlobalAccount(t *testing.T) {
template := `
authorization {
users [
{user: anonymous}
{user: user1, password: %s}
]
}
no_auth_user: anonymous
jetstream: enabled
`
conf := createConfFile(t, []byte(fmt.Sprintf(template, "pwd")))
defer os.Remove(conf)

s, _ := RunServerWithConfig(conf)
defer s.Shutdown()

mset, err := s.GlobalAccount().AddStream(&server.StreamConfig{Name: "foo"})
if err != nil {
t.Fatalf("Unexpected error adding stream: %v", err)
}
defer mset.Delete()

if err := ioutil.WriteFile(conf, []byte(fmt.Sprintf(template, "pwd2")), 0666); err != nil {
t.Fatalf("Error writing config: %v", err)
}

if err := s.Reload(); err != nil {
t.Fatalf("Error during config reload: %v", err)
}

// Try to add a new stream to the global account
mset2, err := s.GlobalAccount().AddStream(&server.StreamConfig{Name: "bar"})
if err != nil {
t.Fatalf("Unexpected error adding stream: %v", err)
}
defer mset2.Delete()
}

0 comments on commit 4e6d600

Please sign in to comment.