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

Function TestReconnectErrHandler

test/conn_test.go:1102–1129  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1100}
1101
1102func TestReconnectErrHandler(t *testing.T) {
1103 handler := func(ch chan bool) func(*nats.Conn, error) {
1104 return func(*nats.Conn, error) {
1105 ch <- true
1106 }
1107 }
1108 t.Run("with RetryOnFailedConnect, MaxReconnects(-1), no connection", func(t *testing.T) {
1109 opts := test.DefaultTestOptions
1110 // Server should not be reachable to test this one
1111 opts.Port = 4223
1112 s := RunServerWithOptions(&opts)
1113 defer s.Shutdown()
1114
1115 reconnectErr := make(chan bool)
1116
1117 nc, err := nats.Connect(nats.DefaultURL,
1118 nats.ReconnectErrHandler(handler(reconnectErr)),
1119 nats.RetryOnFailedConnect(true),
1120 nats.MaxReconnects(-1))
1121 if err != nil {
1122 t.Fatalf("Unexpected error: %v", err)
1123 }
1124 defer nc.Close()
1125 if err = Wait(reconnectErr); err != nil {
1126 t.Fatal("Timeout waiting for reconnect error handler")
1127 }
1128 })
1129}
1130
1131func TestConnectHandler(t *testing.T) {
1132 handler := func(ch chan bool) func(*nats.Conn) {

Callers

nothing calls this directly

Calls 5

ConnectMethod · 0.80
FatalfMethod · 0.80
RunServerWithOptionsFunction · 0.70
WaitFunction · 0.70
CloseMethod · 0.45

Tested by

no test coverage detected