feat: drain readiness before graceful shutdown
This commit is contained in:
@@ -22,6 +22,26 @@ func TestHealthSeparatesLivenessAndReadiness(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadinessEntersDrainBeforeShutdown(t *testing.T) {
|
||||
checks := 0
|
||||
readiness := NewReadiness(func(context.Context) error {
|
||||
checks++
|
||||
return nil
|
||||
})
|
||||
server := New("127.0.0.1:0", readiness.Check)
|
||||
ready := httptest.NewRecorder()
|
||||
server.Handler.ServeHTTP(ready, httptest.NewRequest(http.MethodGet, "/health/ready", nil))
|
||||
if ready.Code != http.StatusOK || checks != 1 {
|
||||
t.Fatalf("before drain: status=%d checks=%d", ready.Code, checks)
|
||||
}
|
||||
readiness.BeginDrain()
|
||||
draining := httptest.NewRecorder()
|
||||
server.Handler.ServeHTTP(draining, httptest.NewRequest(http.MethodGet, "/health/ready", nil))
|
||||
if draining.Code != http.StatusServiceUnavailable || checks != 1 || strings.Contains(draining.Body.String(), "server is draining") {
|
||||
t.Fatalf("during drain: status=%d checks=%d body=%s", draining.Code, checks, draining.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestVersionIsPublicAndBounded(t *testing.T) {
|
||||
server := New("127.0.0.1:0", nil)
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
Reference in New Issue
Block a user