Fix completeConnection + fix monitor test.

Don't check what is sent back. The point is that the client should be fully initialized at this point.
We can't ensure using metrics that the "check" connection is gone since in some tests, the server is started and clients auto-reconnect to it.
For tests that depend on the number of clients connected (such as the monitor one), have specific code for those tests.
This commit is contained in:
Ivan Kozlovic
2016-02-03 18:08:52 -07:00
parent 0a4da78f38
commit 437458e13e
3 changed files with 23 additions and 14 deletions

View File

@@ -177,6 +177,17 @@ 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

@@ -28,7 +28,6 @@ func completeConnection(conn net.Conn) error {
defer conn.Close()
buf := bufio.NewReader(conn)
resp := ""
// Consume the INFO protocol
_, err := buf.ReadString('\n')
@@ -37,13 +36,13 @@ func completeConnection(conn net.Conn) error {
_, err = conn.Write([]byte("PING\r\n"))
}
if err == nil {
// Expect a PONG
resp, err = buf.ReadString('\n')
// 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')
}
if err != nil || resp != "PONG\r\n" {
return err
}
return nil
return err
}
// New Go Routine based server

View File

@@ -82,7 +82,6 @@ func completeConnection(conn net.Conn) error {
defer conn.Close()
buf := bufio.NewReader(conn)
resp := ""
// Consume the INFO protocol
_, err := buf.ReadString('\n')
@@ -91,13 +90,13 @@ func completeConnection(conn net.Conn) error {
_, err = conn.Write([]byte("PING\r\n"))
}
if err == nil {
// Expect a PONG
resp, err = buf.ReadString('\n')
// 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')
}
if err != nil || resp != "PONG\r\n" {
return err
}
return nil
return err
}
// New Go Routine based server with auth