Files
coredns/plugin/health/health_test.go
Miek Gieben c778b3a67c plugin/health: remove ability to poll other plugins (#2547)
* plugin/health: remove ability to poll other plugins

This mechanism defeats the purpose any plugin (mostly) caching can still
be alive, we can probably forward queries still. Don't poll plugins,
just tell the world we're up and running.

It was only actually used in kubernetes; and there specifically would
mean any network hiccup would NACK the entire server health.

Fixes: #2534

Signed-off-by: Miek Gieben <miek@miek.nl>

* update docs based on feedback

Signed-off-by: Miek Gieben <miek@miek.nl>
2019-03-07 22:13:47 +00:00

50 lines
1.1 KiB
Go

package health
import (
"fmt"
"io/ioutil"
"net/http"
"testing"
"time"
)
func TestHealth(t *testing.T) {
h := newHealth(":0")
if err := h.OnStartup(); err != nil {
t.Fatalf("Unable to startup the health server: %v", err)
}
defer h.OnFinalShutdown()
// Reconstruct the http address based on the port allocated by operating system.
address := fmt.Sprintf("http://%s%s", h.ln.Addr().String(), path)
response, err := http.Get(address)
if err != nil {
t.Fatalf("Unable to query %s: %v", address, err)
}
if response.StatusCode != 200 {
t.Errorf("Invalid status code: expecting '200', got '%d'", response.StatusCode)
}
content, err := ioutil.ReadAll(response.Body)
if err != nil {
t.Fatalf("Unable to get response body from %s: %v", address, err)
}
response.Body.Close()
if string(content) != ok {
t.Errorf("Invalid response body: expecting 'OK', got '%s'", string(content))
}
}
func TestHealthLameduck(t *testing.T) {
h := newHealth(":0")
h.lameduck = 250 * time.Millisecond
if err := h.OnStartup(); err != nil {
t.Fatalf("Unable to startup the health server: %v", err)
}
h.OnFinalShutdown()
}