| 3052 | } |
| 3053 | |
| 3054 | func TestRetryOnFailedConnectReconnectErrCB(t *testing.T) { |
| 3055 | errChan := make(chan error, 10) |
| 3056 | |
| 3057 | nc, err := nats.Connect(nats.DefaultURL, |
| 3058 | nats.RetryOnFailedConnect(true), |
| 3059 | nats.MaxReconnects(0), // Limited retries for faster test |
| 3060 | nats.ReconnectWait(10*time.Millisecond), |
| 3061 | nats.ReconnectErrHandler(func(_ *nats.Conn, err error) { |
| 3062 | errChan <- err |
| 3063 | }), |
| 3064 | ) |
| 3065 | if err != nil { |
| 3066 | t.Fatalf("Unexpected error: %v", err) |
| 3067 | } |
| 3068 | defer nc.Close() |
| 3069 | |
| 3070 | // Verify the first error is the initial connection error |
| 3071 | select { |
| 3072 | case err := <-errChan: |
| 3073 | if !errors.Is(err, nats.ErrNoServers) { |
| 3074 | t.Fatalf("Expected ErrNoServers for initial connection failure, got: %v", err) |
| 3075 | } |
| 3076 | case <-time.After(200 * time.Millisecond): |
| 3077 | t.Fatal("Should have received initial connection error in ReconnectErrCB") |
| 3078 | } |
| 3079 | } |
| 3080 | |
| 3081 | func TestRetryOnFailedConnectWithAuthError(t *testing.T) { |
| 3082 | o := test.DefaultTestOptions |