(t *testing.T)
| 1100 | } |
| 1101 | |
| 1102 | func 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 | |
| 1131 | func TestConnectHandler(t *testing.T) { |
| 1132 | handler := func(ch chan bool) func(*nats.Conn) { |
nothing calls this directly
no test coverage detected