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

Function TestReconnectOnFlusherError

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

Source from the content-addressed store, hash-verified

2082}
2083
2084func TestReconnectOnFlusherError(t *testing.T) {
2085 if runtime.GOOS == "windows" {
2086 t.SkipNow()
2087 }
2088
2089 for _, tc := range []struct {
2090 name string
2091 withOption bool
2092 noReconnect bool
2093 wantReconnect bool
2094 wantClosed bool
2095 }{
2096 {"enabled", true, false, true, false},
2097 {"disabled", false, false, false, false},
2098 {"no_reconnect", true, true, false, true},
2099 } {
2100 t.Run(tc.name, func(t *testing.T) {
2101 s := RunDefaultServer()
2102 defer s.Shutdown()
2103
2104 fakeAddr := startStalledMockServer(t)
2105
2106 reconnectedCh := make(chan struct{}, 1)
2107 closedCh := make(chan struct{}, 1)
2108 asyncErrCh := make(chan error, 1)
2109
2110 opts := []nats.Option{
2111 nats.SetCustomDialer(&lowWriteBufferDialer{}),
2112 nats.FlusherTimeout(15 * time.Millisecond),
2113 nats.MaxReconnects(10),
2114 nats.DontRandomize(),
2115 nats.ReconnectHandler(func(_ *nats.Conn) {
2116 select {
2117 case reconnectedCh <- struct{}{}:
2118 default:
2119 }
2120 }),
2121 nats.ClosedHandler(func(_ *nats.Conn) {
2122 select {
2123 case closedCh <- struct{}{}:
2124 default:
2125 }
2126 }),
2127 nats.ErrorHandler(func(_ *nats.Conn, _ *nats.Subscription, err error) {
2128 select {
2129 case asyncErrCh <- err:
2130 default:
2131 }
2132 }),
2133 }
2134 if tc.withOption {
2135 opts = append(opts, nats.ReconnectOnFlusherError())
2136 }
2137 if tc.noReconnect {
2138 opts = append(opts, nats.NoReconnect())
2139 }
2140
2141 nc, err := nats.Connect(

Callers

nothing calls this directly

Calls 14

startStalledMockServerFunction · 0.85
WaitOnChannelFunction · 0.85
ReconnectHandlerMethod · 0.80
ClosedHandlerMethod · 0.80
ErrorHandlerMethod · 0.80
ConnectMethod · 0.80
FatalfMethod · 0.80
ConnectedUrlMethod · 0.80
IsClosedMethod · 0.80
RunDefaultServerFunction · 0.70
StopMethod · 0.65
PublishMethod · 0.65

Tested by

no test coverage detected