mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 08:23:45 +00:00
fix(multiplayer): gate API readiness on database
This commit is contained in:
@@ -1487,6 +1487,59 @@ func TestMetricsEndpointExportsBoundedAPILatencyAndSkipsItsOwnScrape(t *testing.
|
||||
}
|
||||
}
|
||||
|
||||
func TestControlPlaneLivenessAndDatastoreReadinessAreIndependent(t *testing.T) {
|
||||
ready := false
|
||||
checks := 0
|
||||
limiter, err := NewRateLimiter(1, time.Minute, 8)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
service := &Service{
|
||||
RateLimiter: limiter,
|
||||
Now: func() time.Time { return time.Unix(1000, 0) },
|
||||
ReadinessCheck: func(context.Context) error {
|
||||
checks++
|
||||
if !ready {
|
||||
return errors.New("database unavailable")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
handler := service.Handler()
|
||||
status := func(method, path string) int {
|
||||
recorder := httptest.NewRecorder()
|
||||
handler.ServeHTTP(recorder, httptest.NewRequest(method, path, nil))
|
||||
return recorder.Code
|
||||
}
|
||||
if got := status(http.MethodGet, "/healthz"); got != http.StatusOK {
|
||||
t.Fatalf("liveness during datastore outage = %d", got)
|
||||
}
|
||||
if got := status(http.MethodGet, "/readyz"); got != http.StatusServiceUnavailable {
|
||||
t.Fatalf("readiness during datastore outage = %d", got)
|
||||
}
|
||||
ready = true
|
||||
if got := status(http.MethodGet, "/readyz"); got != http.StatusOK {
|
||||
t.Fatalf("recovered readiness = %d", got)
|
||||
}
|
||||
if got := status(http.MethodGet, "/healthz"); got != http.StatusOK {
|
||||
t.Fatalf("repeated probe was incorrectly rate limited: %d", got)
|
||||
}
|
||||
if checks != 2 {
|
||||
t.Fatalf("readiness checks = %d", checks)
|
||||
}
|
||||
if got := status(http.MethodPost, "/readyz"); got != http.StatusMethodNotAllowed {
|
||||
t.Fatalf("readiness mutation status = %d", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestControlPlaneReadinessFailsClosedWithoutCheck(t *testing.T) {
|
||||
recorder := httptest.NewRecorder()
|
||||
(&Service{}).Handler().ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/readyz", nil))
|
||||
if recorder.Code != http.StatusServiceUnavailable {
|
||||
t.Fatalf("unconfigured readiness status = %d", recorder.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProbeAPIUsesServerEvidenceAndRejectsClientRTTField(t *testing.T) {
|
||||
now := time.Unix(1000, 0).UTC()
|
||||
sessions := domain.NewSessionStore()
|
||||
|
||||
Reference in New Issue
Block a user