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

Function TestRequestMultipleReplies

test/nats_test.go:864–906  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

862}
863
864func TestRequestMultipleReplies(t *testing.T) {
865 o := natsserver.DefaultTestOptions
866 o.Port = -1
867 s := RunServerWithOptions(&o)
868 defer s.Shutdown()
869
870 nc, err := nats.Connect(fmt.Sprintf("nats://%s:%d", o.Host, o.Port))
871 if err != nil {
872 t.Fatalf("Error on connect: %v", err)
873 }
874 defer nc.Close()
875
876 response := []byte("I will help you")
877 nc.Subscribe("foo", func(m *nats.Msg) {
878 m.Respond(response)
879 m.Respond(response)
880 })
881 nc.Flush()
882
883 nc2, err := nats.Connect(fmt.Sprintf("nats://%s:%d", o.Host, o.Port))
884 if err != nil {
885 t.Fatalf("Error on connect: %v", err)
886 }
887 defer nc2.Close()
888
889 errCh := make(chan error, 1)
890 // Send a request on bar and expect nothing
891 go func() {
892 if m, err := nc2.Request("bar", nil, 500*time.Millisecond); m != nil || err == nil {
893 errCh <- fmt.Errorf("Expected no reply, got m=%+v err=%v", m, err)
894 return
895 }
896 errCh <- nil
897 }()
898
899 // Send a request on foo, we use only one of the 2 replies
900 if _, err := nc2.Request("foo", nil, time.Second); err != nil {
901 t.Fatalf("Received an error on Request test: %s", err)
902 }
903 if e := <-errCh; e != nil {
904 t.Fatal(e.Error())
905 }
906}
907
908func TestGetRTT(t *testing.T) {
909 s := RunServerOnPort(-1)

Callers

nothing calls this directly

Calls 10

ConnectMethod · 0.80
FatalfMethod · 0.80
ErrorfMethod · 0.80
RunServerWithOptionsFunction · 0.70
SubscribeMethod · 0.65
RespondMethod · 0.65
ErrorMethod · 0.65
CloseMethod · 0.45
FlushMethod · 0.45
RequestMethod · 0.45

Tested by

no test coverage detected