Replace all changes with simple 25ms delay after connection close.

This commit is contained in:
Ivan Kozlovic
2016-02-03 18:58:42 -07:00
parent 437458e13e
commit eb0eabff04
3 changed files with 21 additions and 78 deletions

View File

@@ -177,17 +177,6 @@ func TestConnz(t *testing.T) {
s := runMonitorServer(DEFAULT_HTTP_PORT)
defer s.Shutdown()
// Wait a bit to make sure that the "client" that was created
// by the connection checking that the server is started is gone.
end := time.Now().Add(5 * time.Second)
for time.Now().Before(end) {
if s.NumClients() > 0 {
time.Sleep(10 * time.Millisecond)
} else {
break
}
}
url := fmt.Sprintf("http://localhost:%d/", DEFAULT_HTTP_PORT)
resp, err := http.Get(url + "connz")
if err != nil {

View File

@@ -3,7 +3,6 @@
package server
import (
"bufio"
"net"
"testing"
"time"
@@ -19,32 +18,6 @@ var DefaultOptions = Options{
NoSigs: true,
}
// completeConnection ensures that the server has fully processed (and assigned
// a client id) to the connection created to check that the server has started.
// This is important for tests that expect connections to have a predictable
// value.
func completeConnection(conn net.Conn) error {
// Close the connection on exit
defer conn.Close()
buf := bufio.NewReader(conn)
// Consume the INFO protocol
_, err := buf.ReadString('\n')
if err == nil {
// Send a PING
_, err = conn.Write([]byte("PING\r\n"))
}
if err == nil {
// Expect a PONG, but could be -ERR. We don't really care,
// the point is that if we received something, the client
// is initialized.
_, err = buf.ReadString('\n')
}
return err
}
// New Go Routine based server
func RunServer(opts *Options) *Server {
if opts == nil {
@@ -72,9 +45,12 @@ func RunServer(opts *Options) *Server {
time.Sleep(50 * time.Millisecond)
continue
}
if err := completeConnection(conn); err != nil {
break
}
conn.Close()
// Wait a bit to give a chance to the server to remove this
// "client" from its state, which may otherwise interfere with
// some tests.
time.Sleep(25 * time.Millisecond)
return s
}
panic("Unable to start NATS Server in Go Routine")

View File

@@ -3,7 +3,6 @@
package test
import (
"bufio"
"crypto/rand"
"encoding/hex"
"encoding/json"
@@ -73,32 +72,6 @@ func RunServerWithConfig(configFile string) (srv *server.Server, opts *server.Op
return
}
// completeConnection ensures that the server has fully processed (and assigned
// a client id) to the connection created to check that the server has started.
// This is important for tests that expect connections to have a predictable
// value.
func completeConnection(conn net.Conn) error {
// Close the connection on exit
defer conn.Close()
buf := bufio.NewReader(conn)
// Consume the INFO protocol
_, err := buf.ReadString('\n')
if err == nil {
// Send a PING
_, err = conn.Write([]byte("PING\r\n"))
}
if err == nil {
// Expect a PONG, but could be -ERR. We don't really care,
// the point is that if we received something, the client
// is initialized.
_, err = buf.ReadString('\n')
}
return err
}
// New Go Routine based server with auth
func RunServerWithAuth(opts *server.Options, auth server.Auth) *server.Server {
if opts == nil {
@@ -130,9 +103,11 @@ func RunServerWithAuth(opts *server.Options, auth server.Auth) *server.Server {
time.Sleep(50 * time.Millisecond)
continue
}
if err := completeConnection(conn); err != nil {
break
}
conn.Close()
// Wait a bit to give a chance to the server to remove this
// "client" from its state, which may otherwise interfere with
// some tests.
time.Sleep(25 * time.Millisecond)
return s
}
panic("Unable to start NATS Server in Go Routine")
@@ -161,10 +136,11 @@ func startServer(t tLogger, port int, other string) *natsServer {
return nil
}
} else {
if err := completeConnection(c); err != nil {
t.Fatalf("Error trying to connect to %s: %v", natsServerExe, err)
return nil
}
c.Close()
// Wait a bit to give a chance to the server to remove this
// "client" from its state, which may otherwise interfere with
// some tests.
time.Sleep(25 * time.Millisecond)
break
}
}
@@ -242,9 +218,11 @@ func checkSocket(t tLogger, addr string, wait time.Duration) {
time.Sleep(50 * time.Millisecond)
continue
}
if err := completeConnection(conn); err != nil {
break
}
conn.Close()
// Wait a bit to give a chance to the server to remove this
// "client" from its state, which may otherwise interfere with
// some tests.
time.Sleep(25 * time.Millisecond)
return
}
// We have failed to bind the socket in the time allowed.