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

Function TestAsyncSubscriberStarvation

test/sub_test.go:715–745  ·  view source on GitHub ↗

Test to make sure that we can send and async receive messages on different subjects within a callback.

(t *testing.T)

Source from the content-addressed store, hash-verified

713// Test to make sure that we can send and async receive messages on
714// different subjects within a callback.
715func TestAsyncSubscriberStarvation(t *testing.T) {
716 s := RunDefaultServer()
717 defer s.Shutdown()
718
719 nc := NewDefaultConnection(t)
720 defer nc.Close()
721
722 // Helper
723 nc.Subscribe("helper", func(m *nats.Msg) {
724 nc.Publish(m.Reply, []byte("Hello"))
725 })
726
727 ch := make(chan bool)
728
729 // Kickoff
730 nc.Subscribe("start", func(m *nats.Msg) {
731 // Helper Response
732 response := nats.NewInbox()
733 nc.Subscribe(response, func(_ *nats.Msg) {
734 ch <- true
735 })
736 nc.PublishRequest("helper", response, []byte("Help Me!"))
737 })
738
739 nc.Publish("start", []byte("Begin"))
740 nc.Flush()
741
742 if e := Wait(ch); e != nil {
743 t.Fatal("Was stalled inside of callback waiting on another callback")
744 }
745}
746
747func TestAsyncSubscribersOnClose(t *testing.T) {
748 s := RunDefaultServer()

Callers

nothing calls this directly

Calls 9

NewInboxMethod · 0.80
RunDefaultServerFunction · 0.70
NewDefaultConnectionFunction · 0.70
WaitFunction · 0.70
SubscribeMethod · 0.65
PublishMethod · 0.65
CloseMethod · 0.45
PublishRequestMethod · 0.45
FlushMethod · 0.45

Tested by

no test coverage detected