MCPcopy
hub / github.com/grafana/dskit / TestTCPTransportWriterAcquireTimeout

Function TestTCPTransportWriterAcquireTimeout

kv/memberlist/tcp_transport_test.go:124–156  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

122}
123
124func TestTCPTransportWriterAcquireTimeout(t *testing.T) {
125 // Listen for TCP connections on a random port
126 listener, err := net.Listen("tcp", "127.0.0.1:0")
127 require.NoError(t, err)
128 defer listener.Close()
129
130 logs := &concurrency.SyncBuffer{}
131 logger := log.NewLogfmtLogger(logs)
132
133 cfg := TCPTransportConfig{}
134 flagext.DefaultValues(&cfg)
135 cfg.BindAddrs = getLocalhostAddrs()
136 cfg.MaxConcurrentWrites = 1
137 cfg.AcquireWriterTimeout = 1 * time.Millisecond // very short timeout
138 transport, err := NewTCPTransport(cfg, logger, nil)
139 require.NoError(t, err)
140
141 writeCt := 100
142 var reqWg sync.WaitGroup
143 for i := 0; i < writeCt; i++ {
144 reqWg.Add(1)
145 go func() {
146 defer reqWg.Done()
147 transport.WriteTo([]byte("test"), listener.Addr().String()) // nolint:errcheck
148 }()
149 }
150 reqWg.Wait()
151
152 require.NoError(t, transport.Shutdown())
153 gotErrorCt := strings.Count(logs.String(), "WriteTo failed to acquire a writer. Dropping message")
154 assert.Less(t, gotErrorCt, writeCt, "expected to have less errors (%d) than total writes (%d). Some writes should pass.", gotErrorCt, writeCt)
155 assert.NotZero(t, gotErrorCt, "expected errors, got none")
156}
157
158func TestFinalAdvertiseAddr(t *testing.T) {
159 tests := map[string]struct {

Callers

nothing calls this directly

Calls 13

WriteToMethod · 0.95
ShutdownMethod · 0.95
StringMethod · 0.95
DefaultValuesFunction · 0.92
getLocalhostAddrsFunction · 0.85
NewTCPTransportFunction · 0.85
CloseMethod · 0.65
AddMethod · 0.65
DoneMethod · 0.65
StringMethod · 0.65
WaitMethod · 0.45
CountMethod · 0.45

Tested by

no test coverage detected