mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 18:53:43 -04:00
plugin/health: add lameduck mode (#1379)
* plugin/health: add lameduck mode Add a way to configure lameduck more, i.e. set health to false, stop polling plugins. Then wait for a duration before shutting down. As the health middleware is configured early on in the plugin list, it will hold up all other shutdown, meaning we still answer queries. * Add New * More tests * golint * remove confusing text
This commit is contained in:
@@ -5,12 +5,13 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/coredns/coredns/plugin/erratic"
|
||||
)
|
||||
|
||||
func TestHealth(t *testing.T) {
|
||||
h := health{Addr: ":0"}
|
||||
h := newHealth(":0")
|
||||
h.h = append(h.h, &erratic.Erratic{})
|
||||
|
||||
if err := h.OnStartup(); err != nil {
|
||||
@@ -18,6 +19,11 @@ func TestHealth(t *testing.T) {
|
||||
}
|
||||
defer h.OnShutdown()
|
||||
|
||||
go func() {
|
||||
<-h.pollstop
|
||||
return
|
||||
}()
|
||||
|
||||
// Reconstruct the http address based on the port allocated by operating system.
|
||||
address := fmt.Sprintf("http://%s%s", h.ln.Addr().String(), path)
|
||||
|
||||
@@ -50,3 +56,22 @@ func TestHealth(t *testing.T) {
|
||||
t.Errorf("Invalid response body: expecting 'OK', got '%s'", string(content))
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealthLameduck(t *testing.T) {
|
||||
h := newHealth(":0")
|
||||
h.lameduck = 250 * time.Millisecond
|
||||
h.h = append(h.h, &erratic.Erratic{})
|
||||
|
||||
if err := h.OnStartup(); err != nil {
|
||||
t.Fatalf("Unable to startup the health server: %v", err)
|
||||
}
|
||||
|
||||
// Both these things are behind a sync.Once, fake reading from the channels.
|
||||
go func() {
|
||||
<-h.pollstop
|
||||
<-h.stop
|
||||
return
|
||||
}()
|
||||
|
||||
h.OnShutdown()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user