Example #1
0
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)
			}
		}
	})
}
Example #2
0
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)
			}
		}
	})
}
Example #3
0
	"errors"
	"net"
	"testing"
	"time"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"wx.com/redis/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
			}