@@ -11292,3 +11292,74 @@ func TestLeafNodeNoAccPanicOnProcessLeafNodeConnect(t *testing.T) {
1129211292 t .Fatal ("Server should not have shutdown" )
1129311293 }
1129411294}
11295+
11296+ func TestLeafNodeSpokeConnectAdvisory (t * testing.T ) {
11297+ confHub := createConfFile (t , []byte (`
11298+ listen: 127.0.0.1:-1
11299+ accounts {
11300+ SYS: {users: [{user: sys, password: pwd}]}
11301+ USER: {users: [{user: user, password: pwd}]}
11302+ }
11303+ system_account: SYS
11304+ leafnodes {
11305+ listen: 127.0.0.1:-1
11306+ no_advertise: true
11307+ authorization { timeout: 0.5 }
11308+ }
11309+ ` ))
11310+ hub , hubOpts := RunServerWithConfig (confHub )
11311+ defer hub .Shutdown ()
11312+ hubPort := hubOpts .Port
11313+ hubLeafPort := hubOpts .LeafNode .Port
11314+
11315+ confSpoke := createConfFile (t , []byte (fmt .Sprintf (`
11316+ listen: 127.0.0.1:-1
11317+ accounts {
11318+ SYS: {users: [{user: sys, password: pwd}]}
11319+ USER: {users: [{user: user, password: pwd}]}
11320+ }
11321+ system_account: SYS
11322+ leafnodes {
11323+ reconnect: "50ms"
11324+ remotes: [
11325+ {url: "nats://user:pwd@127.0.0.1:%d", account: USER},
11326+ {url: "nats://sys:pwd@127.0.0.1:%d", account: SYS},
11327+ ]
11328+ }
11329+ ` , hubLeafPort , hubLeafPort )))
11330+ spoke , spokeOpts := RunServerWithConfig (confSpoke )
11331+ defer spoke .Shutdown ()
11332+
11333+ checkLeafNodeConnectedCount (t , hub , 2 )
11334+ checkLeafNodeConnectedCount (t , spoke , 2 )
11335+
11336+ // Subscribe on spoke's system account for USER account events
11337+ nc := natsConnect (t , fmt .Sprintf ("nats://sys:pwd@127.0.0.1:%d" , spokeOpts .Port ))
11338+ defer nc .Close ()
11339+ cSub := natsSubSync (t , nc , "$SYS.ACCOUNT.USER.CONNECT" )
11340+ dSub := natsSubSync (t , nc , "$SYS.ACCOUNT.USER.DISCONNECT" )
11341+ nc .Flush ()
11342+
11343+ // Shut down hub, spoke should emit DISCONNECT
11344+ hub .Shutdown ()
11345+ checkLeafNodeConnectedCount (t , spoke , 0 )
11346+ msg , err := dSub .NextMsg (time .Second )
11347+ require_NoError (t , err )
11348+ var dm DisconnectEventMsg
11349+ require_NoError (t , json .Unmarshal (msg .Data , & dm ))
11350+ require_Equal (t , dm .Client .Kind , "Leafnode" )
11351+
11352+ // Restart hub on the same ports so spoke can reconnect
11353+ hubOpts .Port = hubPort
11354+ hubOpts .LeafNode .Port = hubLeafPort
11355+ hub = RunServer (hubOpts )
11356+ defer hub .Shutdown ()
11357+ checkLeafNodeConnectedCount (t , spoke , 2 )
11358+
11359+ // Spoke should emit CONNECT advisory on reconnect
11360+ msg , err = cSub .NextMsg (time .Second )
11361+ require_NoError (t , err )
11362+ var cm ConnectEventMsg
11363+ require_NoError (t , json .Unmarshal (msg .Data , & cm ))
11364+ require_Equal (t , cm .Client .Kind , "Leafnode" )
11365+ }
0 commit comments