MCPcopy
hub / github.com/grafana/dskit / TestCleanUnhealthy

Function TestCleanUnhealthy

ring/client/pool_test.go:132–172  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

130}
131
132func TestCleanUnhealthy(t *testing.T) {
133 tcs := []struct {
134 maxConcurrent int
135 }{
136 {maxConcurrent: 0}, // if not set, defaults to 16
137 {maxConcurrent: 1},
138 }
139 for _, tc := range tcs {
140 t.Run(fmt.Sprintf("max concurrent %d", tc.maxConcurrent), func(t *testing.T) {
141 goodAddrs := []string{"good1", "good2"}
142 badAddrs := []string{"bad1", "bad2"}
143 clients := map[string]*poolMember{}
144 for _, addr := range goodAddrs {
145 clients[addr] = &poolMember{client: mockClient{happy: true, status: grpc_health_v1.HealthCheckResponse_SERVING}}
146 }
147 for _, addr := range badAddrs {
148 clients[addr] = &poolMember{client: mockClient{happy: false, status: grpc_health_v1.HealthCheckResponse_NOT_SERVING}}
149 }
150
151 cfg := PoolConfig{
152 MaxConcurrentHealthChecks: tc.maxConcurrent,
153 CheckInterval: 1 * time.Second,
154 HealthCheckTimeout: 5 * time.Millisecond,
155 }
156 pool := NewPool("test", cfg, nil, nil, nil, log.NewNopLogger())
157 pool.members = clients
158 pool.cleanUnhealthy()
159
160 for _, addr := range badAddrs {
161 if _, ok := pool.members[addr]; ok {
162 t.Errorf("Found bad client after clean: %s\n", addr)
163 }
164 }
165 for _, addr := range goodAddrs {
166 if _, ok := pool.members[addr]; !ok {
167 t.Errorf("Could not find good client after clean: %s\n", addr)
168 }
169 }
170 })
171 }
172}
173
174func TestCleanUnhealthyWithGracePeriod(t *testing.T) {
175 const alwaysGood = "always-good"

Callers

nothing calls this directly

Calls 4

cleanUnhealthyMethod · 0.95
RunMethod · 0.80
ErrorfMethod · 0.80
NewPoolFunction · 0.70

Tested by

no test coverage detected