reverseproxy: skip unavailable upstream with a single weighted_round_robin weight (#8320)
With fewer than two weights, WeightedRoundRobinSelection returned the first upstream without checking that it is available.pull/8344/head
parent
cce035d7ad
commit
aeea18be86
|
|
@ -146,6 +146,9 @@ func (r *WeightedRoundRobinSelection) Select(pool UpstreamPool, _ *http.Request,
|
|||
return nil
|
||||
}
|
||||
if len(r.Weights) < 2 {
|
||||
if !pool[0].Available() {
|
||||
return nil
|
||||
}
|
||||
return pool[0]
|
||||
}
|
||||
var index, totalWeight int
|
||||
|
|
|
|||
|
|
@ -148,6 +148,24 @@ func TestWeightedRoundRobinPolicyFewerWeightsThanUpstreams(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestWeightedRoundRobinPolicySingleWeight(t *testing.T) {
|
||||
pool := testPool()
|
||||
wrrPolicy := WeightedRoundRobinSelection{
|
||||
Weights: []int{1},
|
||||
totalWeight: 1,
|
||||
}
|
||||
req, _ := http.NewRequest("GET", "/", nil)
|
||||
|
||||
if h := wrrPolicy.Select(pool, req, nil); h != pool[0] {
|
||||
t.Errorf("got %v, want the only weighted host %v", h, pool[0])
|
||||
}
|
||||
|
||||
pool[0].setHealthy(false)
|
||||
if h := wrrPolicy.Select(pool, req, nil); h != nil {
|
||||
t.Errorf("got %v, want nil when the only weighted host is unavailable", h)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWeightedRoundRobinSelection_Validate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
|
|
|||
Loading…
Reference in New Issue