diff --git a/server/configs/reload/reload.conf b/server/configs/reload/reload.conf index cecfc2135c..5e6c89c206 100644 --- a/server/configs/reload/reload.conf +++ b/server/configs/reload/reload.conf @@ -1,42 +1,4 @@ - -# Simple config file - -listen: localhost:4242 - -http: 8222 - -authorization { - user: derek - password: bella - timeout: 1 -} - # logging options debug: false -trace: false +trace: false # enable tracing on reload logtime: false -log_file: "/tmp/gnatsd.log" -syslog: true -remote_syslog: "udp://foo.com:33" - -# pid file -pid_file: "/tmp/gnatsd.pid" - -# prof_port -prof_port: 6543 - -# max_connections -max_connections: 100 - -# maximum control line -max_control_line: 2048 - -# maximum payload -max_payload: 65536 - -# ping interval and no pong threshold -ping_interval: 60 -ping_max: 3 - -# how long server can block on a socket write to a client -write_deadline: "3s" diff --git a/server/configs/reload/reload_unsupported.conf b/server/configs/reload/reload_unsupported.conf index 9f31c4e8e8..6c94268fff 100644 --- a/server/configs/reload/reload_unsupported.conf +++ b/server/configs/reload/reload_unsupported.conf @@ -1,42 +1,4 @@ - -# Simple config file - -listen: localhost:4242 - -http: 8222 - -authorization { - user: derek - password: bella - timeout: 1 -} - # logging options -debug: true +debug: true # debug not supported on config reload trace: false logtime: false -log_file: "/tmp/gnatsd.log" -syslog: true -remote_syslog: "udp://foo.com:33" - -# pid file -pid_file: "/tmp/gnatsd.pid" - -# prof_port -prof_port: 6543 - -# max_connections -max_connections: 100 - -# maximum control line -max_control_line: 2048 - -# maximum payload -max_payload: 65536 - -# ping interval and no pong threshold -ping_interval: 60 -ping_max: 3 - -# how long server can block on a socket write to a client -write_deadline: "3s" diff --git a/server/configs/reload/test.conf b/server/configs/reload/test.conf index 85e4f60cd0..41b239be59 100644 --- a/server/configs/reload/test.conf +++ b/server/configs/reload/test.conf @@ -1,42 +1,4 @@ - -# Simple config file - -listen: localhost:4242 - -http: 8222 - -authorization { - user: derek - password: bella - timeout: 1 -} - # logging options debug: false trace: true logtime: false -log_file: "/tmp/gnatsd.log" -syslog: true -remote_syslog: "udp://foo.com:33" - -# pid file -pid_file: "/tmp/gnatsd.pid" - -# prof_port -prof_port: 6543 - -# max_connections -max_connections: 100 - -# maximum control line -max_control_line: 2048 - -# maximum payload -max_payload: 65536 - -# ping interval and no pong threshold -ping_interval: 60 -ping_max: 3 - -# how long server can block on a socket write to a client -write_deadline: "3s" diff --git a/server/log.go b/server/log.go index 4ddb6da1cb..c110ede3ce 100644 --- a/server/log.go +++ b/server/log.go @@ -15,9 +15,9 @@ var trace int32 var debug int32 var log = struct { - sync.Mutex + *sync.Mutex logger Logger -}{} +}{Mutex: new(sync.Mutex)} // Logger interface of the NATS Server type Logger interface { diff --git a/server/reload_test.go b/server/reload_test.go index 0791824306..921c355424 100644 --- a/server/reload_test.go +++ b/server/reload_test.go @@ -28,32 +28,25 @@ func TestConfigReloadUnsupported(t *testing.T) { golden := &Options{ ConfigFile: config, - Host: "localhost", - Port: 4242, - Username: "derek", - Password: "bella", + Host: "0.0.0.0", + Port: 4222, AuthTimeout: 1.0, Debug: false, Trace: true, Logtime: false, - HTTPPort: 8222, - LogFile: "/tmp/gnatsd.log", - PidFile: "/tmp/gnatsd.pid", - ProfPort: 6543, - Syslog: true, - RemoteSyslog: "udp://foo.com:33", - MaxControlLine: 2048, - MaxPayload: 65536, - MaxConn: 100, - PingInterval: 60 * time.Second, - MaxPingsOut: 3, - WriteDeadline: 3 * time.Second, + MaxControlLine: 1024, + MaxPayload: 1048576, + MaxConn: 65536, + PingInterval: 2 * time.Minute, + MaxPingsOut: 2, + WriteDeadline: 2 * time.Second, } processOptions(golden) if err := os.Symlink("./configs/reload/test.conf", config); err != nil { t.Fatalf("Error creating symlink: %v", err) } + defer os.Remove(config) opts, err := ProcessConfigFile(config) if err != nil { t.Fatalf("Error processing config file: %v", err) @@ -72,11 +65,6 @@ func TestConfigReloadUnsupported(t *testing.T) { if err := os.Symlink("./configs/reload/reload_unsupported.conf", config); err != nil { t.Fatalf("Error creating symlink: %v", err) } - defer func() { - if err := os.Remove(config); err != nil { - t.Fatalf("Error deleting symlink: %v", err) - } - }() // This should fail because `debug` cannot be changed. if err := server.Reload(); err == nil { @@ -100,32 +88,25 @@ func TestConfigReloadInvalidConfig(t *testing.T) { golden := &Options{ ConfigFile: config, - Host: "localhost", - Port: 4242, - Username: "derek", - Password: "bella", + Host: "0.0.0.0", + Port: 4222, AuthTimeout: 1.0, Debug: false, Trace: true, Logtime: false, - HTTPPort: 8222, - LogFile: "/tmp/gnatsd.log", - PidFile: "/tmp/gnatsd.pid", - ProfPort: 6543, - Syslog: true, - RemoteSyslog: "udp://foo.com:33", - MaxControlLine: 2048, - MaxPayload: 65536, - MaxConn: 100, - PingInterval: 60 * time.Second, - MaxPingsOut: 3, - WriteDeadline: 3 * time.Second, + MaxControlLine: 1024, + MaxPayload: 1048576, + MaxConn: 65536, + PingInterval: 2 * time.Minute, + MaxPingsOut: 2, + WriteDeadline: 2 * time.Second, } processOptions(golden) if err := os.Symlink("./configs/reload/test.conf", config); err != nil { t.Fatalf("Error creating symlink: %v", err) } + defer os.Remove(config) opts, err := ProcessConfigFile(config) if err != nil { t.Fatalf("Error processing config file: %v", err) @@ -144,11 +125,6 @@ func TestConfigReloadInvalidConfig(t *testing.T) { if err := os.Symlink("./configs/reload/invalid.conf", config); err != nil { t.Fatalf("Error creating symlink: %v", err) } - defer func() { - if err := os.Remove(config); err != nil { - t.Fatalf("Error deleting symlink: %v", err) - } - }() // This should fail because the new config should not parse. if err := server.Reload(); err == nil { @@ -164,6 +140,14 @@ func TestConfigReloadInvalidConfig(t *testing.T) { // Ensure Reload returns nil and the config is changed on success. func TestConfigReload(t *testing.T) { + // The server package uses a global logger that gets configured by calls to + // server.ConfigureLogger(). We need to restore it to prevent side effects. + // TODO: Consider getting rid of global logger. + logBefore := log + defer func() { + log = logBefore + }() + dir, err := os.Getwd() if err != nil { t.Fatalf("Error getting working directory: %v", err) @@ -172,32 +156,25 @@ func TestConfigReload(t *testing.T) { golden := &Options{ ConfigFile: config, - Host: "localhost", - Port: 4242, - Username: "derek", - Password: "bella", + Host: "0.0.0.0", + Port: 4222, AuthTimeout: 1.0, Debug: false, Trace: true, Logtime: false, - HTTPPort: 8222, - LogFile: "/tmp/gnatsd.log", - PidFile: "/tmp/gnatsd.pid", - ProfPort: 6543, - Syslog: true, - RemoteSyslog: "udp://foo.com:33", - MaxControlLine: 2048, - MaxPayload: 65536, - MaxConn: 100, - PingInterval: 60 * time.Second, - MaxPingsOut: 3, - WriteDeadline: 3 * time.Second, + MaxControlLine: 1024, + MaxPayload: 1048576, + MaxConn: 65536, + PingInterval: 2 * time.Minute, + MaxPingsOut: 2, + WriteDeadline: 2 * time.Second, } processOptions(golden) if err := os.Symlink("./configs/reload/test.conf", config); err != nil { t.Fatalf("Error creating symlink: %v", err) } + defer os.Remove(config) opts, err := ProcessConfigFile(config) if err != nil { t.Fatalf("Error processing config file: %v", err) @@ -216,11 +193,6 @@ func TestConfigReload(t *testing.T) { if err := os.Symlink("./configs/reload/reload.conf", config); err != nil { t.Fatalf("Error creating symlink: %v", err) } - defer func() { - if err := os.Remove(config); err != nil { - t.Fatalf("Error deleting symlink: %v", err) - } - }() // Should change `trace` to false. if err := server.Reload(); err != nil {