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

Function TestWSConcurrentConns

test/ws_test.go:184–223  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

182}
183
184func TestWSConcurrentConns(t *testing.T) {
185 sopts := testWSGetDefaultOptions(t, false)
186 s := RunServerWithOptions(sopts)
187 defer s.Shutdown()
188
189 url := fmt.Sprintf("ws://127.0.0.1:%d", sopts.Websocket.Port)
190
191 total := 50
192 errCh := make(chan error, total)
193 wg := sync.WaitGroup{}
194 wg.Add(total)
195 for i := 0; i < total; i++ {
196 go func() {
197 defer wg.Done()
198
199 nc, err := nats.Connect(url)
200 if err != nil {
201 errCh <- fmt.Errorf("Error on connect: %v", err)
202 return
203 }
204 defer nc.Close()
205
206 sub, err := nc.SubscribeSync(nuid.Next())
207 if err != nil {
208 errCh <- fmt.Errorf("Error on subscribe: %v", err)
209 return
210 }
211 nc.Publish(sub.Subject, []byte("here"))
212 if _, err := sub.NextMsg(time.Second); err != nil {
213 errCh <- err
214 }
215 }()
216 }
217 wg.Wait()
218 select {
219 case e := <-errCh:
220 t.Fatal(e.Error())
221 default:
222 }
223}
224
225func TestWSCompression(t *testing.T) {
226 msgSize := rand.Intn(40000)

Callers

nothing calls this directly

Calls 12

testWSGetDefaultOptionsFunction · 0.85
ConnectMethod · 0.80
ErrorfMethod · 0.80
NextMsgMethod · 0.80
RunServerWithOptionsFunction · 0.70
AddMethod · 0.65
DoneMethod · 0.65
SubscribeSyncMethod · 0.65
NextMethod · 0.65
PublishMethod · 0.65
ErrorMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected