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

Function TestConnectPool

proxycore/connpool_test.go:32–72  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

30)
31
32func TestConnectPool(t *testing.T) {
33 var server MockServer
34
35 ctx, cancel := context.WithCancel(context.Background())
36 defer cancel()
37
38 const supported = primitive.ProtocolVersion2
39
40 err := server.Serve(ctx, supported, MockHost{
41 IP: "127.0.0.1",
42 Port: 9042,
43 }, nil)
44 require.NoError(t, err)
45
46 p, err := connectPool(ctx, connPoolConfig{
47 Endpoint: &defaultEndpoint{addr: "127.0.0.1:9042"},
48 SessionConfig: SessionConfig{
49 ReconnectPolicy: NewReconnectPolicy(),
50 NumConns: 2,
51 Version: supported,
52 ConnectTimeout: 10 * time.Second,
53 HeartBeatInterval: 30 * time.Second,
54 IdleTimeout: 60 * time.Second,
55 },
56 })
57 require.NoError(t, err)
58
59 cl1 := p.leastBusyConn()
60 assert.NotNil(t, cl1) // Expect a valid connection
61
62 var wg sync.WaitGroup
63 wg.Add(1)
64
65 err = cl1.Send(&testInflightRequest{&wg})
66 require.NoError(t, err)
67
68 cl2 := p.leastBusyConn()
69 assert.True(t, cl1 != cl2) // cl1 is no longer the least busy
70
71 wg.Wait()
72}
73
74func TestConnectPool_NoServer(t *testing.T) {
75 var server MockServer

Callers

nothing calls this directly

Calls 6

ServeMethod · 0.95
connectPoolFunction · 0.85
NewReconnectPolicyFunction · 0.85
SendMethod · 0.65
leastBusyConnMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected