(t *testing.T)
| 30 | ) |
| 31 | |
| 32 | func 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 | |
| 74 | func TestConnectPool_NoServer(t *testing.T) { |
| 75 | var server MockServer |
nothing calls this directly
no test coverage detected