(t *testing.T)
| 130 | } |
| 131 | |
| 132 | func 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 | |
| 174 | func TestCleanUnhealthyWithGracePeriod(t *testing.T) { |
| 175 | const alwaysGood = "always-good" |
nothing calls this directly
no test coverage detected