mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-17 11:24:44 -07:00
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:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
13
test/test.go
13
test/test.go
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user