MCPcopy
hub / github.com/nats-io/nats.go / TestServerPoolUpdatedWhenRouteGoesAway

Function TestServerPoolUpdatedWhenRouteGoesAway

test/cluster_test.go:704–898  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

702}
703
704func TestServerPoolUpdatedWhenRouteGoesAway(t *testing.T) {
705 if err := serverVersionAtLeast(1, 0, 7); err != nil {
706 t.Skip(err.Error())
707 }
708 s1Opts := test.DefaultTestOptions
709 s1Opts.Host = "127.0.0.1"
710 s1Opts.Port = 4222
711 s1Opts.Cluster.Host = "127.0.0.1"
712 s1Opts.Cluster.Port = 6222
713 s1Opts.Routes = server.RoutesFromStr("nats://127.0.0.1:6223,nats://127.0.0.1:6224")
714 s1 := test.RunServer(&s1Opts)
715 defer s1.Shutdown()
716
717 s1Url := "nats://127.0.0.1:4222"
718 s2Url := "nats://127.0.0.1:4223"
719 s3Url := "nats://127.0.0.1:4224"
720
721 ch := make(chan bool, 1)
722 chch := make(chan bool, 1)
723 connHandler := func(_ *nats.Conn) {
724 chch <- true
725 }
726 nc, err := nats.Connect(s1Url,
727 nats.ReconnectHandler(connHandler),
728 nats.DiscoveredServersHandler(func(_ *nats.Conn) {
729 ch <- true
730 }))
731 if err != nil {
732 t.Fatalf("Error on connect")
733 }
734
735 s2Opts := test.DefaultTestOptions
736 s2Opts.Host = "127.0.0.1"
737 s2Opts.Port = s1Opts.Port + 1
738 s2Opts.Cluster.Host = "127.0.0.1"
739 s2Opts.Cluster.Port = 6223
740 s2Opts.Routes = server.RoutesFromStr("nats://127.0.0.1:6222,nats://127.0.0.1:6224")
741 s2 := test.RunServer(&s2Opts)
742 defer s2.Shutdown()
743
744 // Wait to be notified
745 if err := Wait(ch); err != nil {
746 t.Fatal("New server callback was not invoked")
747 }
748
749 checkPool := func(expected []string) {
750 // Don't use discovered here, but Servers to have the full list.
751 // Also, there may be cases where the mesh is not formed yet,
752 // so try again on failure.
753 var (
754 ds []string
755 timeout = time.Now().Add(5 * time.Second)
756 )
757 for time.Now().Before(timeout) {
758 ds = nc.Servers()
759 if len(ds) == len(expected) {
760 m := make(map[string]struct{}, len(ds))
761 for _, url := range ds {

Callers

nothing calls this directly

Calls 13

serverVersionAtLeastFunction · 0.85
ConnectMethod · 0.80
ReconnectHandlerMethod · 0.80
FatalfMethod · 0.80
ServersMethod · 0.80
ConnectedUrlMethod · 0.80
ClosedHandlerMethod · 0.80
WaitFunction · 0.70
stackFatalfFunction · 0.70
ErrorMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected