Test to make sure that we can send and async receive messages on different subjects within a callback.
(t *testing.T)
| 713 | // Test to make sure that we can send and async receive messages on |
| 714 | // different subjects within a callback. |
| 715 | func 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 | |
| 747 | func TestAsyncSubscribersOnClose(t *testing.T) { |
| 748 | s := RunDefaultServer() |
nothing calls this directly
no test coverage detected