(t *testing.T)
| 3079 | } |
| 3080 | |
| 3081 | func TestRetryOnFailedConnectWithAuthError(t *testing.T) { |
| 3082 | o := test.DefaultTestOptions |
| 3083 | o.Username = "user" |
| 3084 | o.Password = "password" |
| 3085 | s := RunServerWithOptions(&o) |
| 3086 | defer s.Shutdown() |
| 3087 | |
| 3088 | errChan := make(chan error, 10) |
| 3089 | closedCh := make(chan bool, 1) |
| 3090 | |
| 3091 | // Try to connect without credentials |
| 3092 | nc, err := nats.Connect(nats.DefaultURL, |
| 3093 | nats.RetryOnFailedConnect(true), |
| 3094 | nats.MaxReconnects(2), |
| 3095 | nats.ReconnectWait(10*time.Millisecond), |
| 3096 | nats.ReconnectErrHandler(func(_ *nats.Conn, err error) { |
| 3097 | errChan <- err |
| 3098 | }), |
| 3099 | nats.ClosedHandler(func(_ *nats.Conn) { |
| 3100 | closedCh <- true |
| 3101 | }), |
| 3102 | ) |
| 3103 | if err != nil { |
| 3104 | t.Fatalf("Unexpected error: %v", err) |
| 3105 | } |
| 3106 | defer nc.Close() |
| 3107 | |
| 3108 | // Wait for closed due to auth failure |
| 3109 | select { |
| 3110 | case <-closedCh: |
| 3111 | case <-time.After(500 * time.Millisecond): |
| 3112 | t.Fatal("Connection should have closed due to auth failure") |
| 3113 | } |
| 3114 | |
| 3115 | select { |
| 3116 | case err := <-errChan: |
| 3117 | if !errors.Is(err, nats.ErrAuthorization) { |
| 3118 | t.Fatalf("Expected ErrAuthorization for auth failure, got: %v", err) |
| 3119 | } |
| 3120 | case <-time.After(500 * time.Millisecond): |
| 3121 | t.Fatal("Should have received authorization error in ReconnectErrCB") |
| 3122 | } |
| 3123 | } |
| 3124 | |
| 3125 | func TestRetryOnFailedConnectWithTLSError(t *testing.T) { |
| 3126 | opts := test.DefaultTestOptions |
nothing calls this directly
no test coverage detected