From 26ef3f8a7004b936b7c2199f7773b75ff7a2ccba Mon Sep 17 00:00:00 2001 From: miraclesu Date: Tue, 9 May 2017 15:59:34 +0800 Subject: [PATCH] Revise queue msg action We think it marks a queue subscription via QRSID prefix. --- server/route.go | 12 ++++++------ test/routes_test.go | 11 +++-------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/server/route.go b/server/route.go index ff392f05..dee8f464 100644 --- a/server/route.go +++ b/server/route.go @@ -446,8 +446,7 @@ const ( RSID = "RSID" QRSID = "QRSID" - QRSID_PREFIX = QRSID + ":" - QRSID_PREFIX_LEN = len(QRSID_PREFIX) + QRSID_LEN = len(QRSID) ) func (s *Server) routeSidQueueSubscriber(rsid []byte) (*subscription, bool) { @@ -482,17 +481,18 @@ func routeSid(sub *subscription) string { } func parseRouteSid(rsid []byte) (uint64, []byte, bool) { - if !bytes.HasPrefix(rsid, []byte(QRSID_PREFIX)) { + if !bytes.HasPrefix(rsid, []byte(QRSID)) { return 0, nil, false } - for i := QRSID_PREFIX_LEN; i < len(rsid); i++ { + // We don't care what's char of rsid[QRSID_LEN+1], it should be ':' + for i, count := QRSID_LEN+1, len(rsid); i < count; i++ { switch rsid[i] { case ':': - return uint64(parseInt64(rsid[QRSID_PREFIX_LEN:i])), rsid[i+1:], len(rsid[i+1:]) > 0 + return uint64(parseInt64(rsid[QRSID_LEN+1 : i])), rsid[i+1:], true } } - return 0, nil, false + return 0, nil, true } func (s *Server) addRoute(c *client, info *Info) (bool, bool) { diff --git a/test/routes_test.go b/test/routes_test.go index ea6df3b3..c21b50a1 100644 --- a/test/routes_test.go +++ b/test/routes_test.go @@ -399,17 +399,12 @@ func TestRouteQueueSemantics(t *testing.T) { routeSend("PING\r\n") routeExpect(pongRe) - // Should be 3 now, 1 for all normal, and one for specific queue subscriber, - // others for normal - matches = clientExpectMsgs(5) + // Should be 2 now, 1 for all normal, and one for specific queue subscriber. + matches = clientExpectMsgs(2) - // Expect first to be the normal subscriber, next will be the queue one, - // others to be the normal subscriber + // Expect first to be the normal subscriber, next will be the queue one. checkMsg(t, matches[0], "foo", "1", "", "2", "ok") checkMsg(t, matches[1], "foo", "2", "", "2", "ok") - checkMsg(t, matches[2], "foo", "1", "", "2", "ok") - checkMsg(t, matches[3], "foo", "1", "", "2", "ok") - checkMsg(t, matches[4], "foo", "1", "", "2", "ok") } func TestSolicitRouteReconnect(t *testing.T) {