@@ -728,3 +728,58 @@ func TestRoutesToEachOther(t *testing.T) {
728
728
t .Log ("Was not able to get duplicate route this time!" )
729
729
}
730
730
}
731
+
732
+ func TestConnectULRsWithRoutesToEachOther (t * testing.T ) {
733
+ optsA := DefaultOptions ()
734
+ optsA .Host = "127.0.0.1"
735
+ optsA .Cluster .Port = 7246
736
+ optsA .Routes = RoutesFromStr ("nats://127.0.0.1:7247" )
737
+
738
+ optsB := DefaultOptions ()
739
+ optsB .Host = "127.0.0.1"
740
+ optsB .Cluster .Port = 7247
741
+ optsB .Routes = RoutesFromStr ("nats://127.0.0.1:7246" )
742
+
743
+ // Start servers with go routines to increase change of
744
+ // each server connecting to each other at the same time.
745
+ srvA := New (optsA )
746
+ defer srvA .Shutdown ()
747
+
748
+ srvB := New (optsB )
749
+ defer srvB .Shutdown ()
750
+
751
+ go srvA .Start ()
752
+ go srvB .Start ()
753
+
754
+ // Wait for cluster to be formed
755
+ checkClusterFormed (t , srvA , srvB )
756
+
757
+ // Connect to serverB
758
+ url := fmt .Sprintf ("nats://%s" , srvB .Addr ().String ())
759
+ nc , err := nats .Connect (url )
760
+ if err != nil {
761
+ t .Fatalf ("Error on connect: %v" , err )
762
+ }
763
+ defer nc .Close ()
764
+ ds := nc .Servers ()
765
+ if len (ds ) != 2 {
766
+ t .Fatalf ("Expected 2 servers, got %v" , ds )
767
+ }
768
+
769
+ // Shutdown server A and make sure that we are notfied
770
+ // that server A is no longer running.
771
+ srvA .Shutdown ()
772
+ timeout := time .Now ().Add (5 * time .Second )
773
+ ok := false
774
+ for time .Now ().Before (timeout ) {
775
+ ds = nc .Servers ()
776
+ if len (ds ) == 1 {
777
+ ok = true
778
+ break
779
+ }
780
+ time .Sleep (50 * time .Millisecond )
781
+ }
782
+ if ! ok {
783
+ t .Fatalf ("List of servers should be only 1, got %v" , ds )
784
+ }
785
+ }
0 commit comments