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

Function TestReconnectBufSize

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

Source from the content-addressed store, hash-verified

613}
614
615func TestReconnectBufSize(t *testing.T) {
616 s := RunDefaultServer()
617 defer s.Shutdown()
618
619 o := nats.GetDefaultOptions()
620 o.ReconnectBufSize = 32 // 32 bytes
621
622 dch := make(chan bool)
623 o.DisconnectedErrCB = func(_ *nats.Conn, _ error) {
624 dch <- true
625 }
626
627 nc, err := o.Connect()
628 if err != nil {
629 t.Fatalf("Should have connected ok: %v", err)
630 }
631 defer nc.Close()
632
633 err = nc.Flush()
634 if err != nil {
635 t.Fatalf("Error during flush: %v", err)
636 }
637
638 // Force disconnected state.
639 s.Shutdown()
640
641 if e := Wait(dch); e != nil {
642 t.Fatal("DisconnectedErrCB should have been triggered")
643 }
644
645 msg := []byte("food") // 4 bytes paylaod, total proto is 16 bytes
646 // These should work, 2X16 = 32
647 if err := nc.Publish("foo", msg); err != nil {
648 t.Fatalf("Failed to publish message: %v\n", err)
649 }
650 if err := nc.Publish("foo", msg); err != nil {
651 t.Fatalf("Failed to publish message: %v\n", err)
652 }
653
654 // This should fail since we have exhausted the backing buffer.
655 if err := nc.Publish("foo", msg); err == nil {
656 t.Fatalf("Expected to fail to publish message: got no error\n")
657 }
658 nc.Buffered()
659}
660
661// When a cluster is fronted by a single DNS name (desired) but communicates IPs to clients (also desired),
662// and we use TLS, we want to make sure we do the right thing connecting to an IP directly for TLS to work.

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected