From 61b0fec2000284c0897fb6de968ac6217ffcddac Mon Sep 17 00:00:00 2001 From: Ivan Kozlovic Date: Tue, 26 Jul 2016 11:57:16 -0600 Subject: [PATCH] Updated test for corner cases Test when client has not yet sent its CONNECT proto or the first PING when route is added. --- test/routes_test.go | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/test/routes_test.go b/test/routes_test.go index 1f458037..497ee8cb 100644 --- a/test/routes_test.go +++ b/test/routes_test.go @@ -767,8 +767,18 @@ func TestRouteSendAsyncINFOToClients(t *testing.T) { rc, routeSend, routeExpect = createRoute() defer rc.Close() + // Create a client not sending the CONNECT until after route is added + clientNoConnect := createClientConn(t, opts.Host, opts.Port) + defer clientNoConnect.Close() + + // Create a client that does not send the first PING yet + clientNoPing := createClientConn(t, opts.Host, opts.Port) + defer clientNoPing.Close() + clientNoPingSend, clientNoPingExpect := setupConnWithProto(t, clientNoPing, clientProtoInfo) + // The route now has an additional URL routeConnectURLs = append(routeConnectURLs, "localhost:7777") + // This causes the server to add the route and send INFO to clients sendRouteINFO(routeSend, routeExpect, routeConnectURLs) // Expect nothing for old clients @@ -776,4 +786,40 @@ func TestRouteSendAsyncINFOToClients(t *testing.T) { // Expect new client to receive an INFO, and verify content as expected. checkINFOReceived(newClientExpect, routeConnectURLs) + + // Expect nothing yet for client that did not send the PING + expectNothing(t, clientNoPing) + + // Now send the first PING + clientNoPingSend("PING\r\n") + // Should receive PONG followed by INFO + // Receive PONG only first + pongBuf := make([]byte, len("PONG\r\n")) + clientNoPing.SetReadDeadline(time.Now().Add(2 * time.Second)) + n, err := clientNoPing.Read(pongBuf) + clientNoPing.SetReadDeadline(time.Time{}) + if n <= 0 && err != nil { + t.Fatalf("Error reading from conn: %v\n", err) + } + if !pongRe.Match(pongBuf) { + t.Fatalf("Response did not match expected: \n\tReceived:'%q'\n\tExpected:'%s'\n", pongBuf, pongRe) + } + checkINFOReceived(clientNoPingExpect, routeConnectURLs) + + // Have the client that did not send the connect do it now + clientNoConnectSend, clientNoConnectExpect := setupConnWithProto(t, clientNoConnect, clientProtoInfo) + // Send the PING + clientNoConnectSend("PING\r\n") + // Should receive PONG followed by INFO + // Receive PONG only first + clientNoConnect.SetReadDeadline(time.Now().Add(2 * time.Second)) + n, err = clientNoConnect.Read(pongBuf) + clientNoConnect.SetReadDeadline(time.Time{}) + if n <= 0 && err != nil { + t.Fatalf("Error reading from conn: %v\n", err) + } + if !pongRe.Match(pongBuf) { + t.Fatalf("Response did not match expected: \n\tReceived:'%q'\n\tExpected:'%s'\n", pongBuf, pongRe) + } + checkINFOReceived(clientNoConnectExpect, routeConnectURLs) }