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

Function TestReconnectBufSizeDisable

test/reconnect_test.go:786–826  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

784}
785
786func TestReconnectBufSizeDisable(t *testing.T) {
787 s := RunDefaultServer()
788 defer s.Shutdown()
789
790 o := nats.GetDefaultOptions()
791
792 // Disable buffering to always get a synchronous error when publish fails.
793 o.ReconnectBufSize = -1
794
795 dch := make(chan bool)
796 o.DisconnectedErrCB = func(_ *nats.Conn, _ error) {
797 dch <- true
798 }
799
800 nc, err := o.Connect()
801 if err != nil {
802 t.Fatalf("Should have connected ok: %v", err)
803 }
804 defer nc.Close()
805
806 err = nc.Flush()
807 if err != nil {
808 t.Fatalf("Error during flush: %v", err)
809 }
810
811 // Force disconnected state.
812 s.Shutdown()
813
814 if e := Wait(dch); e != nil {
815 t.Fatal("DisconnectedErrCB should have been triggered")
816 }
817
818 msg := []byte("food")
819 if err := nc.Publish("foo", msg); err != nats.ErrReconnectBufExceeded {
820 t.Fatalf("Unexpected error: %v\n", err)
821 }
822 got, _ := nc.Buffered()
823 if got != 0 {
824 t.Errorf("Unexpected buffered bytes: %v", got)
825 }
826}
827
828func TestAuthExpiredReconnect(t *testing.T) {
829 ts := runTrustServer()

Callers

nothing calls this directly

Calls 9

ConnectMethod · 0.80
FatalfMethod · 0.80
BufferedMethod · 0.80
ErrorfMethod · 0.80
RunDefaultServerFunction · 0.70
WaitFunction · 0.70
PublishMethod · 0.65
CloseMethod · 0.45
FlushMethod · 0.45

Tested by

no test coverage detected