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

Function TestRetryOnFailedConnectReconnectErrCB

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

Source from the content-addressed store, hash-verified

3052}
3053
3054func 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
3081func TestRetryOnFailedConnectWithAuthError(t *testing.T) {
3082 o := test.DefaultTestOptions

Callers

nothing calls this directly

Calls 4

ConnectMethod · 0.80
FatalfMethod · 0.80
CloseMethod · 0.45
IsMethod · 0.45

Tested by

no test coverage detected