Skip to content
quarry Artifact [d352b6124b]
Login

Artifact [d352b6124b]

Artifact d352b6124b9dcb60f7869c997669d9f3b4fd030ef1d59e40f3f0c0748ae0e596:


package web

import (
	"strings"
	"testing"
)

// The panel lists each live process with what started it, its age, its
// usual and its memory; a slow one is marked, and an empty forge says
// nothing is running rather than drawing an empty table.
func TestRunningNowPanelNamesEachProcess(t *testing.T) {
	var v opsView
	remarshal(map[string]any{"budgetMs": 500, "running": []map[string]any{
		{"verb": "timeline", "repo": "fossil", "cause": "GET /r/fossil/timeline", "ageMs": 9000, "usualMs": 1100, "rss": 22 << 20, "slow": true},
		{"verb": "ls", "repo": "tcl", "cause": "ingest", "ageMs": 300, "usualMs": 60},
	}}, &v)
	body := renderOps(t, v)
	if !strings.Contains(body, `data-hook="ops-running" data-count="2"`) {
		t.Fatalf("FAIL: no running panel with two rows:\n%s", body)
	}
	if !strings.Contains(body, `data-verb="timeline" data-repo="fossil" data-slow="true"`) ||
		!strings.Contains(body, `data-verb="ls" data-repo="tcl" data-slow="false"`) {
		t.Errorf("FAIL: rows are not marked by slowness:\n%s", body)
	}
	for _, want := range []string{"<code>GET /<wbr>r/<wbr>fossil/<wbr>timeline</code>", ">ingest<", "9.00 s", "1.10 s", "22 MB"} {
		if !strings.Contains(body, want) {
			t.Errorf("FAIL: the panel lacks %q", want)
		}
	}
	empty := renderOps(t, opsView{BudgetMs: 500})
	if !strings.Contains(empty, `data-hook="ops-running" data-count="0"`) || strings.Contains(empty, `class="ops-t ops-running"`) {
		t.Errorf("FAIL: an idle forge draws a table or no panel")
	}
}