1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-31 05:04:23 +03:00

fix: limit the number of connections created (#2441)

* fix: limit the number of connections created

Signed-off-by: monkey92t <golang@88.com>
This commit is contained in:
Monkey
2023-02-14 18:01:53 +08:00
committed by GitHub
parent 0d306237c7
commit 3532f2a414
2 changed files with 45 additions and 11 deletions

View File

@ -327,4 +327,30 @@ var _ = Describe("race", func() {
}
})
})
It("limit the number of connections", func() {
opt := &pool.Options{
Dialer: func(ctx context.Context) (net.Conn, error) {
return &net.TCPConn{}, nil
},
PoolSize: 1000,
MinIdleConns: 50,
PoolTimeout: 3 * time.Second,
}
p := pool.NewConnPool(opt)
var wg sync.WaitGroup
for i := 0; i < opt.PoolSize; i++ {
wg.Add(1)
go func() {
defer wg.Done()
_, _ = p.Get(ctx)
}()
}
wg.Wait()
stats := p.Stats()
Expect(stats.IdleConns).To(Equal(uint32(0)))
Expect(stats.TotalConns).To(Equal(uint32(opt.PoolSize)))
})
})