diff options
-rw-r--r-- | plugin/pkg/healthcheck/healthcheck.go | 4 | ||||
-rw-r--r-- | plugin/pkg/healthcheck/policy_test.go | 24 |
2 files changed, 26 insertions, 2 deletions
diff --git a/plugin/pkg/healthcheck/healthcheck.go b/plugin/pkg/healthcheck/healthcheck.go index 29a904c34..2a1a89478 100644 --- a/plugin/pkg/healthcheck/healthcheck.go +++ b/plugin/pkg/healthcheck/healthcheck.go @@ -212,6 +212,10 @@ func (u *HealthCheck) Select() *UpstreamHost { // normalizeCheckURL creates a proper URL for the health check. func (u *HealthCheck) normalizeCheckURL(name string) string { + if u.Path == "" { + return "" + } + // The DNS server might be an HTTP server. If so, extract its name. hostName := name ret, err := url.Parse(name) diff --git a/plugin/pkg/healthcheck/policy_test.go b/plugin/pkg/healthcheck/policy_test.go index 60ed46b23..d3f03b7e3 100644 --- a/plugin/pkg/healthcheck/policy_test.go +++ b/plugin/pkg/healthcheck/policy_test.go @@ -52,17 +52,16 @@ func TestRegisterPolicy(t *testing.T) { func TestHealthCheck(t *testing.T) { u := &HealthCheck{ Hosts: testPool(), + Path: "/", FailTimeout: 10 * time.Second, MaxFails: 1, } for i, h := range u.Hosts { - u.Hosts[i].Fails = 1 u.Hosts[i].CheckURL = u.normalizeCheckURL(h.Name) } u.healthCheck() - time.Sleep(time.Duration(1 * time.Second)) // sleep a bit, it's async now if u.Hosts[0].Down() { @@ -73,6 +72,27 @@ func TestHealthCheck(t *testing.T) { } } +func TestHealthCheckDisabled(t *testing.T) { + u := &HealthCheck{ + Hosts: testPool(), + FailTimeout: 10 * time.Second, + MaxFails: 1, + } + + for i, h := range u.Hosts { + u.Hosts[i].CheckURL = u.normalizeCheckURL(h.Name) + } + + u.healthCheck() + time.Sleep(time.Duration(1 * time.Second)) // sleep a bit, it's async now + + for i, h := range u.Hosts { + if h.Down() { + t.Errorf("Expected host %d in testpool to not be down with healthchecks disabled.", i+1) + } + } +} + func TestRoundRobinPolicy(t *testing.T) { pool := testPool() rrPolicy := &RoundRobin{} |