7
. "github.com/onsi/ginkgo/v2"
8
. "github.com/onsi/gomega"
9
"google.golang.org/grpc"
10
"google.golang.org/grpc/connectivity"
12
"github.com/kumahq/kuma/pkg/core"
13
"github.com/kumahq/kuma/pkg/intercp/client"
14
"github.com/kumahq/kuma/pkg/test"
17
var _ = Describe("Pool", func() {
18
It("should not create a client when TLS is not configured", func() {
20
pool := client.NewPool(nil, 1*time.Second, core.Now)
23
_, err := pool.Client("http://192.168.0.1")
26
Expect(err).To(Equal(client.TLSNotConfigured))
29
Context("configured with TLS", func() {
31
const idleDeadline = 100 * time.Millisecond
32
var ticks chan time.Time
37
clock = test.NewClock(time.Now())
38
ticks = make(chan time.Time)
39
pool = client.NewPool(func(s string, config *client.TLSConfig) (client.Conn, error) {
41
state: connectivity.Ready,
43
}, idleDeadline, clock.Now)
44
pool.SetTLSConfig(&client.TLSConfig{})
45
ctx, c := context.WithCancel(context.Background())
47
go pool.StartCleanup(ctx, &time.Ticker{C: ticks})
54
It("should keep the connection open", func() {
56
c, err := pool.Client("http://192.168.0.1")
57
Expect(err).ToNot(HaveOccurred())
58
c2, err := pool.Client("http://192.168.0.1")
59
Expect(err).ToNot(HaveOccurred())
62
Expect(c).To(BeIdenticalTo(c2))
65
It("should create a new connection after the previous expired", func() {
67
c, err := pool.Client("http://192.168.0.1")
68
Expect(err).ToNot(HaveOccurred())
71
clock.Add(idleDeadline + 1*time.Millisecond)
74
c2, err := pool.Client("http://192.168.0.1")
75
Expect(err).ToNot(HaveOccurred())
78
Expect(c).NotTo(BeIdenticalTo(c2))
79
Expect(c.(*testConn).closed).To(BeTrue())
82
It("should close broken connection and create a new one", func() {
84
c, err := pool.Client("http://192.168.0.1")
85
Expect(err).ToNot(HaveOccurred())
86
c.(*testConn).state = connectivity.TransientFailure
91
c2, err := pool.Client("http://192.168.0.1")
92
Expect(err).ToNot(HaveOccurred())
95
Expect(c).NotTo(BeIdenticalTo(c2))
96
Expect(c.(*testConn).closed).To(BeTrue())
101
type testConn struct {
104
state connectivity.State
107
var _ client.Conn = &testConn{}
109
func (t *testConn) Close() error {
114
func (t *testConn) GetState() connectivity.State {