mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Multiple routes w/ same Id
This commit is contained in:
@@ -236,9 +236,8 @@ func TestRouteQueueSemantics(t *testing.T) {
|
||||
defer s.Shutdown()
|
||||
|
||||
client := createClientConn(t, opts.Host, opts.Port)
|
||||
defer client.Close()
|
||||
|
||||
clientSend, clientExpect := setupConn(t, client)
|
||||
defer client.Close()
|
||||
|
||||
route := createRouteConn(t, opts.ClusterHost, opts.ClusterPort)
|
||||
expectAuthRequired(t, route)
|
||||
@@ -281,7 +280,6 @@ func TestRouteQueueSemantics(t *testing.T) {
|
||||
expectMsgs(1)
|
||||
|
||||
// We could get one on client
|
||||
|
||||
}
|
||||
|
||||
func TestSolicitRouteReconnect(t *testing.T) {
|
||||
@@ -298,3 +296,43 @@ func TestSolicitRouteReconnect(t *testing.T) {
|
||||
// We expect to get called back..
|
||||
route = acceptRouteConn(t, rUrl.Host, 2*server.DEFAULT_ROUTE_CONNECT)
|
||||
}
|
||||
|
||||
func TestMultipleRoutesSameId(t *testing.T) {
|
||||
s, opts := runRouteServer(t)
|
||||
defer s.Shutdown()
|
||||
|
||||
route1 := createRouteConn(t, opts.ClusterHost, opts.ClusterPort)
|
||||
expectAuthRequired(t, route1)
|
||||
route1Send, route1Expect := setupRouteEx(t, route1, opts, "ROUTE:2222")
|
||||
route1ExpectMsgs := expectMsgsCommand(t, route1Expect)
|
||||
|
||||
route2 := createRouteConn(t, opts.ClusterHost, opts.ClusterPort)
|
||||
expectAuthRequired(t, route2)
|
||||
route2Send, _ := setupRouteEx(t, route2, opts, "ROUTE:2222")
|
||||
|
||||
// Send SUB via route connections
|
||||
sub := "SUB foo RSID:2:22\r\n"
|
||||
route1Send(sub)
|
||||
route2Send(sub)
|
||||
|
||||
// Make sure we do not get anything on a MSG send to a router.
|
||||
// Send MSG proto via route connection
|
||||
route1Send("MSG foo 1 2\r\nok\r\n")
|
||||
|
||||
expectNothing(t, route1)
|
||||
expectNothing(t, route2)
|
||||
|
||||
// Setup a client
|
||||
client := createClientConn(t, opts.Host, opts.Port)
|
||||
clientSend, _ := setupConn(t, client)
|
||||
defer client.Close()
|
||||
|
||||
// Send PUB via client connection
|
||||
clientSend("PUB foo 2\r\nok\r\n")
|
||||
|
||||
// We should only receive on the first route.
|
||||
route1ExpectMsgs(1)
|
||||
|
||||
// Nothing on the second.
|
||||
expectNothing(t, route2)
|
||||
}
|
||||
14
test/test.go
14
test/test.go
@@ -207,20 +207,22 @@ func doRouteAuthConnect(t tLogger, c net.Conn, user, pass, id string) {
|
||||
sendProto(t, c, cs)
|
||||
}
|
||||
|
||||
func setupRoute(t tLogger, c net.Conn, opts *server.Options) (sendFun, expectFun) {
|
||||
func setupRouteEx(t tLogger, c net.Conn, opts *server.Options, id string) (sendFun, expectFun) {
|
||||
user := opts.ClusterUsername
|
||||
pass := opts.ClusterPassword
|
||||
|
||||
u := make([]byte, 16)
|
||||
io.ReadFull(rand.Reader, u)
|
||||
id := fmt.Sprintf("ROUTER:%s", hex.EncodeToString(u))
|
||||
|
||||
doRouteAuthConnect(t, c, user, pass, id)
|
||||
send := sendCommand(t, c)
|
||||
expect := expectCommand(t, c)
|
||||
return send, expect
|
||||
}
|
||||
|
||||
func setupRoute(t tLogger, c net.Conn, opts *server.Options) (sendFun, expectFun) {
|
||||
u := make([]byte, 16)
|
||||
io.ReadFull(rand.Reader, u)
|
||||
id := fmt.Sprintf("ROUTER:%s", hex.EncodeToString(u))
|
||||
return setupRouteEx(t, c, opts, id)
|
||||
}
|
||||
|
||||
func setupConn(t tLogger, c net.Conn) (sendFun, expectFun) {
|
||||
doDefaultConnect(t, c)
|
||||
send := sendCommand(t, c)
|
||||
|
||||
Reference in New Issue
Block a user