0.2.78
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
|
||||
"github.com/ponzischeme89/memby/server/internal/config"
|
||||
"github.com/ponzischeme89/memby/server/internal/recommend"
|
||||
"github.com/ponzischeme89/memby/server/internal/runtimestats"
|
||||
"github.com/ponzischeme89/memby/server/internal/store"
|
||||
)
|
||||
|
||||
@@ -488,18 +489,57 @@ func TestAdminRuntimeMetricsAreProtectedAndReportHeap(t *testing.T) {
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("runtime status = %d: %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
var body adminRuntimeStatus
|
||||
var body runtimestats.Snapshot
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if body.Goroutines < 1 || body.HeapInuse == 0 || body.MemoryLimit <= 0 {
|
||||
if body.Goroutines < 1 || body.Memory.HeapInuse == 0 || body.Memory.MemoryLimit <= 0 {
|
||||
t.Fatalf("runtime metrics = %+v", body)
|
||||
}
|
||||
// The health verdict is the reason this route exists: a count with no verdict beside
|
||||
// it is the number the console could not explain.
|
||||
if body.Health.Level == "" || body.Health.Summary == "" {
|
||||
t.Fatalf("runtime health = %+v", body.Health)
|
||||
}
|
||||
if rec.Header().Get("Cache-Control") != "no-store" {
|
||||
t.Fatalf("cache control = %q", rec.Header().Get("Cache-Control"))
|
||||
}
|
||||
}
|
||||
|
||||
// The breakdown is the answer to "what are those goroutines doing", so the parts must add
|
||||
// up to the whole: a category table that quietly drops a state is worse than no table.
|
||||
func TestAdminGoroutineBreakdownPartitionsTheTotal(t *testing.T) {
|
||||
server := testServer(config.Config{AdminToken: "secret"})
|
||||
req := httptest.NewRequest(http.MethodGet, "/admin/api/runtime/goroutines", nil)
|
||||
req.Header.Set("Authorization", "Bearer secret")
|
||||
rec := httptest.NewRecorder()
|
||||
server.adminRoutes().ServeHTTP(rec, req)
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("goroutine breakdown = %d: %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
var report runtimestats.GoroutineReport
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &report); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if report.Total < 1 {
|
||||
t.Fatalf("total = %d", report.Total)
|
||||
}
|
||||
counted := 0
|
||||
for _, category := range report.Categories {
|
||||
counted += category.Count
|
||||
}
|
||||
if counted != report.Total {
|
||||
t.Fatalf("categories total %d, report total %d", counted, report.Total)
|
||||
}
|
||||
components := 0
|
||||
for _, component := range report.Components {
|
||||
components += component.Count
|
||||
}
|
||||
if components != report.Total {
|
||||
t.Fatalf("components total %d, report total %d", components, report.Total)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdminPageEstablishesPersistentCookie(t *testing.T) {
|
||||
server := testServer(config.Config{
|
||||
AdminToken: "secret", ReleasePublishToken: "release-secret",
|
||||
|
||||
Reference in New Issue
Block a user