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

Function TestSlowChanSubscriber

test/sub_test.go:482–506  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

480}
481
482func TestSlowChanSubscriber(t *testing.T) {
483 s := RunDefaultServer()
484 defer s.Shutdown()
485
486 nc := NewDefaultConnection(t)
487 defer nc.Close()
488
489 // Override default handler for test.
490 nc.SetErrorHandler(func(_ *nats.Conn, _ *nats.Subscription, _ error) {})
491
492 ch := make(chan *nats.Msg, 64)
493 sub, _ := nc.ChanSubscribe("foo", ch)
494 sub.SetPendingLimits(100, 1024)
495
496 for range 200 {
497 nc.Publish("foo", []byte("Hello"))
498 }
499 timeout := 5 * time.Second
500 start := time.Now()
501 nc.FlushTimeout(timeout)
502 elapsed := time.Since(start)
503 if elapsed >= timeout {
504 t.Fatalf("Flush did not return before timeout: %d > %d", elapsed, timeout)
505 }
506}
507
508func TestSlowAsyncSubscriber(t *testing.T) {
509 s := RunDefaultServer()

Callers

nothing calls this directly

Calls 9

SetErrorHandlerMethod · 0.80
SetPendingLimitsMethod · 0.80
FatalfMethod · 0.80
RunDefaultServerFunction · 0.70
NewDefaultConnectionFunction · 0.70
ChanSubscribeMethod · 0.65
PublishMethod · 0.65
CloseMethod · 0.45
FlushTimeoutMethod · 0.45

Tested by

no test coverage detected