Skip to content

Commit

Permalink
caddyhttp: reverseproxy: add test to catch #4135
Browse files Browse the repository at this point in the history
If you revert the last commit, the test will fail.
  • Loading branch information
simaotwx committed Apr 29, 2021
1 parent 838edef commit 5a3e746
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions modules/caddyhttp/reverseproxy/selectionpolicies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,35 @@ func TestIPHashPolicy(t *testing.T) {
if h != nil {
t.Error("Expected ip hash policy host to be nil.")
}

// Reproduce #4135
pool = UpstreamPool{
{Host: new(upstreamHost)},
{Host: new(upstreamHost)},
{Host: new(upstreamHost)},
{Host: new(upstreamHost)},
{Host: new(upstreamHost)},
{Host: new(upstreamHost)},
{Host: new(upstreamHost)},
{Host: new(upstreamHost)},
{Host: new(upstreamHost)},
}
pool[0].SetHealthy(false)
pool[1].SetHealthy(false)
pool[2].SetHealthy(false)
pool[3].SetHealthy(false)
pool[4].SetHealthy(false)
pool[5].SetHealthy(false)
pool[6].SetHealthy(false)
pool[7].SetHealthy(false)
pool[8].SetHealthy(true)

// We should get a result back when there is one healthy host left.
h = ipHash.Select(pool, req, nil)
if h == nil {
// If it is nil, it means we missed a host even though one is available
t.Error("Expected ip hash policy host to not be nil, but it is nil.")
}
}

func TestFirstPolicy(t *testing.T) {
Expand Down

0 comments on commit 5a3e746

Please sign in to comment.