@@ -4875,9 +4875,12 @@ func TestLeafNodeRoutedSubKeyDifferentBetweenLeafSubAndRoutedSub(t *testing.T) {
4875
4875
for _ , test := range []struct {
4876
4876
name string
4877
4877
pinnedAccount string
4878
+ lnocu bool
4878
4879
}{
4879
- {"without pinned account" , _EMPTY_ },
4880
- {"with pinned account" , "accounts: [\" XYZ\" ]" },
4880
+ {"without pinned account" , _EMPTY_ , true },
4881
+ {"with pinned account" , "accounts: [\" XYZ\" ]" , true },
4882
+ {"old server without pinned account" , _EMPTY_ , false },
4883
+ {"old server with pinned account" , "accounts: [\" XYZ\" ]" , false },
4881
4884
} {
4882
4885
t .Run (test .name , func (t * testing.T ) {
4883
4886
leafBConf := `
@@ -4906,6 +4909,20 @@ func TestLeafNodeRoutedSubKeyDifferentBetweenLeafSubAndRoutedSub(t *testing.T) {
4906
4909
4907
4910
checkClusterFormed (t , b1 , b2 )
4908
4911
4912
+ // To make route connections behave like if the server was connected
4913
+ // to an older server, change the routes' lnocu field.
4914
+ if ! test .lnocu {
4915
+ for _ , s := range []* Server {b1 , b2 } {
4916
+ s .mu .RLock ()
4917
+ s .forEachRoute (func (r * client ) {
4918
+ r .mu .Lock ()
4919
+ r .route .lnocu = false
4920
+ r .mu .Unlock ()
4921
+ })
4922
+ s .mu .RUnlock ()
4923
+ }
4924
+ }
4925
+
4909
4926
// This leaf will have a cluster name that matches an account name.
4910
4927
// The idea is to make sure that hub servers are not using incorrect
4911
4928
// keys to differentiate a routed queue interest on subject "A" with
@@ -4954,19 +4971,21 @@ func TestLeafNodeRoutedSubKeyDifferentBetweenLeafSubAndRoutedSub(t *testing.T) {
4954
4971
natsFlush (t , ncA )
4955
4972
4956
4973
// Check the acc.rm on B2
4957
- acc , err := b2 .LookupAccount ("XYZ" )
4974
+ b2Acc , err := b2 .LookupAccount ("XYZ" )
4958
4975
require_NoError (t , err )
4959
4976
4960
4977
rsubKey := keyFromSubWithOrigin (& subscription {subject : []byte ("foo" )})
4961
4978
rqsubKey := keyFromSubWithOrigin (& subscription {subject : []byte ("XYZ" ), queue : []byte ("foo" )})
4962
4979
rlsubKey := keyFromSubWithOrigin (& subscription {origin : []byte ("XYZ" ), subject : []byte ("foo" )})
4963
4980
rlqsubKey := keyFromSubWithOrigin (& subscription {origin : []byte ("XYZ" ), subject : []byte ("XYZ" ), queue : []byte ("foo" )})
4981
+ // Ensure all keys are different
4982
+ require_True (t , rsubKey != rqsubKey && rqsubKey != rlsubKey && rlsubKey != rlqsubKey )
4964
4983
4965
4984
checkFor (t , time .Second , 10 * time .Millisecond , func () error {
4966
- acc .mu .RLock ()
4967
- defer acc .mu .RUnlock ()
4985
+ b2Acc .mu .RLock ()
4986
+ defer b2Acc .mu .RUnlock ()
4968
4987
for _ , key := range []string {rsubKey , rqsubKey , rlsubKey , rlqsubKey } {
4969
- v , ok := acc .rm [key ]
4988
+ v , ok := b2Acc .rm [key ]
4970
4989
if ! ok {
4971
4990
return fmt .Errorf ("Did not find key %q for sub: %+v" , key , sub )
4972
4991
}
@@ -4978,15 +4997,15 @@ func TestLeafNodeRoutedSubKeyDifferentBetweenLeafSubAndRoutedSub(t *testing.T) {
4978
4997
})
4979
4998
4980
4999
// Now check that on B1, we have 2 distinct subs for the route.
4981
- acc , err = b1 .LookupAccount ("XYZ" )
5000
+ b1Acc , err : = b1 .LookupAccount ("XYZ" )
4982
5001
require_NoError (t , err )
4983
5002
4984
5003
var route * client
4985
5004
4986
5005
if test .pinnedAccount == _EMPTY_ {
4987
- acc .mu .RLock ()
4988
- rIdx := acc .routePoolIdx
4989
- acc .mu .RUnlock ()
5006
+ b1Acc .mu .RLock ()
5007
+ rIdx := b1Acc .routePoolIdx
5008
+ b1Acc .mu .RUnlock ()
4990
5009
b1 .mu .RLock ()
4991
5010
b1 .forEachRouteIdx (rIdx , func (r * client ) bool {
4992
5011
route = r
@@ -5014,8 +5033,45 @@ func TestLeafNodeRoutedSubKeyDifferentBetweenLeafSubAndRoutedSub(t *testing.T) {
5014
5033
}
5015
5034
}
5016
5035
route .mu .Unlock ()
5017
- if len (entries ) != 4 {
5018
- return fmt .Errorf ("Expected 4 entries with %q, got this: %q" , "foo" , entries )
5036
+ // With new servers, we expect 4 entries, but with older servers,
5037
+ // we have collisions and have only 2.
5038
+ var expected int
5039
+ if test .lnocu {
5040
+ expected = 4
5041
+ } else {
5042
+ expected = 2
5043
+ }
5044
+ if len (entries ) != expected {
5045
+ return fmt .Errorf ("Expected %d entries with %q, got this: %q" , expected , "foo" , entries )
5046
+ }
5047
+ return nil
5048
+ })
5049
+
5050
+ // Close the connections and expect all gone.
5051
+ ncB2 .Close ()
5052
+ ncA .Close ()
5053
+
5054
+ checkFor (t , time .Second , 10 * time .Millisecond , func () error {
5055
+ b2Acc .mu .RLock ()
5056
+ defer b2Acc .mu .RUnlock ()
5057
+ for _ , key := range []string {rsubKey , rqsubKey , rlsubKey , rlqsubKey } {
5058
+ if _ , ok := b2Acc .rm [key ]; ok {
5059
+ return fmt .Errorf ("Key %q still present" , key )
5060
+ }
5061
+ }
5062
+ return nil
5063
+ })
5064
+ checkFor (t , time .Second , 10 * time .Millisecond , func () error {
5065
+ var entries []string
5066
+ route .mu .Lock ()
5067
+ for key := range route .subs {
5068
+ if strings .Contains (key , "foo" ) {
5069
+ entries = append (entries , key )
5070
+ }
5071
+ }
5072
+ route .mu .Unlock ()
5073
+ if len (entries ) != 0 {
5074
+ return fmt .Errorf ("Still routed subscriptions on %q: %q" , "foo" , entries )
5019
5075
}
5020
5076
return nil
5021
5077
})
0 commit comments