Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Treat committed May 31, 2017
1 parent b95dd5d commit 43ee0ce
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 181 deletions.
40 changes: 1 addition & 39 deletions 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"
40 changes: 1 addition & 39 deletions 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"
38 changes: 0 additions & 38 deletions 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"
4 changes: 2 additions & 2 deletions server/log.go
Expand Up @@ -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 {
Expand Down
98 changes: 35 additions & 63 deletions server/reload_test.go
Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit 43ee0ce

Please sign in to comment.