MCPcopy
hub / github.com/micro/go-micro / TestWatchQueryTopic

Function TestWatchQueryTopic

registry/options_test.go:95–166  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

93}
94
95func TestWatchQueryTopic(t *testing.T) {
96 natsURL := os.Getenv("NATS_URL")
97 if natsURL == "" {
98 log.Println("NATS_URL is undefined - skipping tests")
99 return
100 }
101
102 watchTopic := "custom.test.watch"
103 queryTopic := "custom.test.query"
104 wt := WatchTopic(watchTopic)
105 qt := QueryTopic(queryTopic)
106
107 // connect to NATS and subscribe to the Watch & Query topics where the
108 // registry will publish a msg
109 nopts := nats.GetDefaultOptions()
110 nopts.Servers = setAddrs([]string{natsURL})
111 conn, err := nopts.Connect()
112 if err != nil {
113 t.Fatal(err)
114 }
115
116 wg := sync.WaitGroup{}
117 wg.Add(2)
118
119 okCh := make(chan struct{})
120
121 // Wait until we have received something on both topics
122 go func() {
123 wg.Wait()
124 close(okCh)
125 }()
126
127 // handler just calls wg.Done()
128 rcvdHdlr := func(m *nats.Msg) {
129 wg.Done()
130 }
131
132 _, err = conn.Subscribe(queryTopic, rcvdHdlr)
133 if err != nil {
134 t.Fatal(err)
135 }
136
137 _, err = conn.Subscribe(watchTopic, rcvdHdlr)
138 if err != nil {
139 t.Fatal(err)
140 }
141
142 dummyService := &Service{
143 Name: "TestInitAddr",
144 Version: "1.0.0",
145 }
146
147 reg := NewRegistry(qt, wt, Addrs(natsURL))
148
149 // trigger registry to send out message on watchTopic
150 if err := reg.Register(dummyService); err != nil {
151 t.Fatal(err)
152 }

Callers

nothing calls this directly

Calls 13

RegisterMethod · 0.95
ListServicesMethod · 0.95
WatchTopicFunction · 0.85
QueryTopicFunction · 0.85
NewRegistryFunction · 0.85
FatalMethod · 0.80
DoneMethod · 0.80
AddrsFunction · 0.70
ConnectMethod · 0.65
AddMethod · 0.65
SubscribeMethod · 0.65
setAddrsFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…