|
|
@@ -277,76 +277,6 @@ func BenchmarkProtocolV3(b *testing.B) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func TestRoundRobinConnPoolRoundRobin(t *testing.T) {
|
|
|
- // create 5 test servers
|
|
|
- servers := make([]*TestServer, 5)
|
|
|
- addrs := make([]string, len(servers))
|
|
|
- for n := 0; n < len(servers); n++ {
|
|
|
- servers[n] = NewTestServer(t, defaultProto)
|
|
|
- addrs[n] = servers[n].Address
|
|
|
- defer servers[n].Stop()
|
|
|
- }
|
|
|
-
|
|
|
- // create a new cluster using the policy-based round robin conn pool
|
|
|
- cluster := NewCluster(addrs...)
|
|
|
- cluster.PoolConfig.HostSelectionPolicy = RoundRobinHostPolicy()
|
|
|
- cluster.PoolConfig.ConnSelectionPolicy = RoundRobinConnPolicy()
|
|
|
- cluster.disableControlConn = true
|
|
|
-
|
|
|
- db, err := cluster.CreateSession()
|
|
|
- if err != nil {
|
|
|
- t.Fatalf("failed to create a new session: %v", err)
|
|
|
- }
|
|
|
-
|
|
|
- // Sleep to allow the pool to fill
|
|
|
- time.Sleep(100 * time.Millisecond)
|
|
|
-
|
|
|
- // run concurrent queries against the pool, server usage should
|
|
|
- // be even
|
|
|
- var wg sync.WaitGroup
|
|
|
- wg.Add(5)
|
|
|
- for n := 0; n < 5; n++ {
|
|
|
- go func() {
|
|
|
- defer wg.Done()
|
|
|
-
|
|
|
- for j := 0; j < 5; j++ {
|
|
|
- if err := db.Query("void").Exec(); err != nil {
|
|
|
- t.Errorf("Query failed with error: %v", err)
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
- }()
|
|
|
- }
|
|
|
- wg.Wait()
|
|
|
-
|
|
|
- db.Close()
|
|
|
-
|
|
|
- // wait for the pool to drain
|
|
|
- time.Sleep(100 * time.Millisecond)
|
|
|
- size := db.pool.Size()
|
|
|
- if size != 0 {
|
|
|
- t.Errorf("connection pool did not drain, still contains %d connections", size)
|
|
|
- }
|
|
|
-
|
|
|
- // verify that server usage is even
|
|
|
- diff := 0
|
|
|
- for n := 1; n < len(servers); n++ {
|
|
|
- d := 0
|
|
|
- if servers[n].nreq > servers[n-1].nreq {
|
|
|
- d = int(servers[n].nreq - servers[n-1].nreq)
|
|
|
- } else {
|
|
|
- d = int(servers[n-1].nreq - servers[n].nreq)
|
|
|
- }
|
|
|
- if d > diff {
|
|
|
- diff = d
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if diff > 0 {
|
|
|
- t.Fatalf("expected 0 difference in usage but was %d", diff)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
// This tests that the policy connection pool handles SSL correctly
|
|
|
func TestPolicyConnPoolSSL(t *testing.T) {
|
|
|
srv := NewSSLTestServer(t, defaultProto)
|