func newConnPool(opt *Options) *pool.ConnPool { return pool.NewConnPool( opt.getDialer(), opt.getPoolSize(), opt.getPoolTimeout(), opt.getIdleTimeout(), opt.getIdleCheckFrequency(), ) }
func benchmarkPoolGetPut(b *testing.B, poolSize int) { connPool := pool.NewConnPool(dummyDialer, poolSize, time.Second, time.Hour, time.Hour) connPool.DialLimiter = nil b.ResetTimer() b.RunParallel(func(pb *testing.PB) { for pb.Next() { cn, err := connPool.Get() if err != nil { b.Fatal(err) } if err = connPool.Put(cn); err != nil { b.Fatal(err) } } }) }
func benchmarkPoolGetRemove(b *testing.B, poolSize int) { connPool := pool.NewConnPool(dummyDialer, poolSize, time.Second, time.Hour, time.Hour) connPool.DialLimiter = nil removeReason := errors.New("benchmark") b.ResetTimer() b.RunParallel(func(pb *testing.PB) { for pb.Next() { cn, err := connPool.Get() if err != nil { b.Fatal(err) } if err := connPool.Remove(cn, removeReason); err != nil { b.Fatal(err) } } }) }
"errors" "net" "testing" "time" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "gopkg.in/redis.v3/internal/pool" ) var _ = Describe("ConnPool", func() { var connPool *pool.ConnPool BeforeEach(func() { connPool = pool.NewConnPool( dummyDialer, 10, time.Hour, time.Millisecond, time.Millisecond) }) AfterEach(func() { connPool.Close() }) It("rate limits dial", func() { var rateErr error for i := 0; i < 1000; i++ { cn, err := connPool.Get() if err != nil { rateErr = err break }