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

Function TestRetryOnFailedConnectWithTLSError

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

Source from the content-addressed store, hash-verified

3123}
3124
3125func TestRetryOnFailedConnectWithTLSError(t *testing.T) {
3126 opts := test.DefaultTestOptions
3127 opts.Port = 4222
3128 tc := &server.TLSConfigOpts{
3129 CertFile: "./configs/certs/server.pem",
3130 KeyFile: "./configs/certs/key.pem",
3131 CaFile: "./configs/certs/ca.pem",
3132 }
3133 var err error
3134 if opts.TLSConfig, err = server.GenTLSConfig(tc); err != nil {
3135 t.Fatalf("Can't build TLCConfig: %v", err)
3136 }
3137 opts.TLSTimeout = 0.0001
3138
3139 s := RunServerWithOptions(&opts)
3140 defer s.Shutdown()
3141
3142 connectedCh := make(chan bool, 1)
3143 nc, err := nats.Connect(nats.DefaultURL,
3144 nats.Secure(&tls.Config{InsecureSkipVerify: true}),
3145 nats.RetryOnFailedConnect(true),
3146 nats.MaxReconnects(-1),
3147 nats.ReconnectWait(15*time.Millisecond),
3148 nats.ConnectHandler(func(_ *nats.Conn) {
3149 connectedCh <- true
3150 }),
3151 nats.NoCallbacksAfterClientClose())
3152 if err != nil {
3153 t.Fatalf("Unexpected error: %v", err)
3154 }
3155 defer nc.Close()
3156
3157 // Wait for several failed attempts
3158 time.Sleep(100 * time.Millisecond)
3159 // Replace tls timeout to a reasonable value.
3160 s.Shutdown()
3161 opts.TLSTimeout = 2.0
3162 s = RunServerWithOptions(&opts)
3163 defer s.Shutdown()
3164
3165 select {
3166 case <-connectedCh:
3167 case <-time.After(time.Second):
3168 t.Fatal("Should have connected")
3169 }
3170}
3171
3172func TestConnStatusChangedEvents(t *testing.T) {
3173 t.Run("default events", func(t *testing.T) {

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected