MCPcopy Create free account
hub / github.com/datastax/cql-proxy / TestClientConn_Inflight

Function TestClientConn_Inflight

proxycore/clientconn_test.go:286–336  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

284}
285
286func TestClientConn_Inflight(t *testing.T) {
287 server := &MockServer{
288 Handlers: NewMockRequestHandlers(MockRequestHandlers{
289 primitive.OpCodeQuery: func(cl *MockClient, frm *frame.Frame) message.Message {
290 time.Sleep(100 * time.Millisecond) // Give time to make sure we're able to count inflight requests
291 if msg := cl.InterceptQuery(frm.Header, frm.Body.Message.(*message.Query)); msg != nil {
292 return msg
293 } else {
294 return &message.RowsResult{
295 Metadata: &message.RowsMetadata{
296 ColumnCount: 0,
297 },
298 Data: message.RowSet{},
299 }
300 }
301 },
302 }),
303 }
304
305 const supported = primitive.ProtocolVersion4
306
307 ctx, cancel := context.WithCancel(context.Background())
308 defer cancel()
309
310 err := server.Serve(ctx, supported, MockHost{
311 IP: "127.0.0.1",
312 Port: 9042,
313 HostID: mockHostID,
314 }, nil)
315 require.NoError(t, err)
316
317 cl, err := ConnectClient(ctx, NewEndpoint("127.0.0.1:9042"), ClientConnConfig{})
318 require.NoError(t, err)
319
320 _, err = cl.Handshake(ctx, supported, nil)
321 require.NoError(t, err)
322
323 const expected = 10
324
325 var wg sync.WaitGroup
326 wg.Add(expected)
327
328 for i := 0; i < 10; i++ {
329 err := cl.Send(&testInflightRequest{&wg})
330 require.NoError(t, err)
331 }
332
333 assert.Equal(t, int32(expected), cl.Inflight()) // Verify async inflight requests
334 wg.Wait()
335 assert.Equal(t, int32(0), cl.Inflight()) // Should be 0 after they complete
336}
337
338func TestClientConn_Unprepared(t *testing.T) {
339 const (

Callers

nothing calls this directly

Calls 9

ServeMethod · 0.95
NewMockRequestHandlersFunction · 0.85
ConnectClientFunction · 0.85
NewEndpointFunction · 0.85
InterceptQueryMethod · 0.80
HandshakeMethod · 0.80
InflightMethod · 0.80
SendMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected