race fixes, tests

This commit is contained in:
Derek Collison
2015-06-16 12:48:50 -07:00
parent ed9d7337ce
commit d9c7392c4d
6 changed files with 15 additions and 8 deletions

View File

@@ -1,7 +1,8 @@
FROM google/golang:1.3
FROM google/golang:1.4
MAINTAINER Derek Collison <derek@apcera.com>
# Note need CGO_ENABLED=0 go build -a -installsuffix cgo for 1.4
RUN CGO_ENABLED=0 go get -a -ldflags '-s' github.com/apcera/gnatsd
COPY Dockerfile.final /gopath/bin/Dockerfile

View File

@@ -57,7 +57,7 @@ func Fatalf(format string, v ...interface{}) {
}
func Debugf(format string, v ...interface{}) {
if debug == 0 {
if atomic.LoadInt32(&debug) == 0 {
return
}
@@ -67,7 +67,7 @@ func Debugf(format string, v ...interface{}) {
}
func Tracef(format string, v ...interface{}) {
if trace == 0 {
if atomic.LoadInt32(&trace) == 0 {
return
}

View File

@@ -9,6 +9,7 @@ import (
"net"
"net/url"
"regexp"
"sync/atomic"
"time"
)
@@ -202,7 +203,7 @@ func (s *Server) addRoute(c *client) bool {
func (s *Server) broadcastToRoutes(proto string) {
var arg []byte
if trace == 1 {
if atomic.LoadInt32(&trace) == 1 {
arg = []byte(proto[:len(proto)-LEN_CR_LF])
}
s.mu.Lock()

View File

@@ -205,6 +205,8 @@ func TestClusterDoubleMsgs(t *testing.T) {
defer srvA.Shutdown()
defer srvB.Shutdown()
time.Sleep(50 * time.Millisecond)
clientA1 := createClientConn(t, optsA.Host, optsA.Port)
defer clientA1.Close()

View File

@@ -157,7 +157,10 @@ func TestRouteForwardsMsgFromClients(t *testing.T) {
expectMsgs := expectMsgsCommand(t, routeExpect)
// Eat the CONNECT and INFO protos
routeExpect(infoRe)
buf := routeExpect(connectRe)
if !infoRe.Match(buf) {
routeExpect(infoRe)
}
// Send SUB via route connection
routeSend("SUB foo RSID:2:22\r\n")
@@ -356,7 +359,7 @@ func TestSolicitRouteReconnect(t *testing.T) {
// We expect to get called back..
route = acceptRouteConn(t, rUrl.Host, 2*server.DEFAULT_ROUTE_CONNECT)
defer route.Close()
route.Close()
}
func TestMultipleRoutesSameId(t *testing.T) {
@@ -436,6 +439,7 @@ func TestRouteResendsLocalSubsOnReconnect(t *testing.T) {
routeSend, routeExpect := setupRouteEx(t, route, opts, "ROUTE:4222")
// Expect to see the local sub echoed through after we send our INFO.
time.Sleep(50 * time.Millisecond)
buf := routeExpect(infoRe)
// Generate our own INFO so we can send one to trigger the local subs.

View File

@@ -279,8 +279,7 @@ var (
unsubRe = regexp.MustCompile(`UNSUB\s+([^\s]+)(\s+(\d+))?\r\n`)
unsubmaxRe = regexp.MustCompile(`UNSUB\s+([^\s]+)(\s+(\d+))\r\n`)
unsubnomaxRe = regexp.MustCompile(`UNSUB\s+([^\s]+)\r\n`)
connectRe = regexp.MustCompile(`CONNECT\s+([^\r\n]+)\r\n`)
connectRe = regexp.MustCompile(`CONNECT\s+([^\r\n]+)\r\n`)
)
const (