Files
llmgw/internal/slurm/accounts_test.go
T
Ilker ManapandClaude Opus 5.5 fcda4d3f85
CI / test (push) Failing after 7m24s
Slurm's jobs in llmgw's accounting: projects as accounts, jobs priced
With slurm.users llmgw, each project is a Slurm account, its organization's
and team's above it, with the project's members and its team's and
organization's on it; slurm.conf holds a job to its user's accounts. The
controller's agent keeps them with sacctmgr, only what it made, and reports
the jobs that ended in the last day; the leader records each once, its
GPU-hours (core-hours without cards) priced at auth.gpu_hour_cost into its
project's usage as model slurm/PARTITION.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 11:54:01 +01:00

90 lines
3.4 KiB
Go

package slurm
import (
"slices"
"testing"
"time"
)
func TestAccountsFollowTheTree(t *testing.T) {
projects := []TenancyProject{
{ID: "p1", Name: "deneme", TeamID: "t1", TeamName: "arge", OrgID: "o1", OrgName: "Test"},
{ID: "p2", Name: "Görüntü İşleme", TeamID: "t1", TeamName: "arge", OrgID: "o1", OrgName: "Test"},
{ID: "p3", Name: "x", TeamID: "t2", TeamName: "ops", OrgID: "o2", OrgName: "Other"},
}
members := []TenancyMember{
{UserID: "u-ayse", Scope: "project", ScopeID: "p1"},
{UserID: "u-ada", Scope: "team", ScopeID: "t1"},
{UserID: "u-bob", Scope: "org", ScopeID: "o2"},
{UserID: "u-nologin", Scope: "project", ScopeID: "p1"},
}
logins := map[string]string{"u-ayse": "ayse", "u-ada": "ada", "u-bob": "bob"}
got := Accounts(projects, members, logins)
var names []string
by := map[string]Account{}
for _, a := range got {
names = append(names, a.Name)
by[a.Name] = a
}
// Parents first, each before its children.
want := []string{"other", "other-ops", "other-ops-x", "test", "test-arge", "test-arge-goruntu_isleme", "test-arge-deneme"}
if !slices.Equal(names, want) {
t.Fatalf("names %v", names)
}
if a := by["test-arge-deneme"]; a.Parent != "test-arge" || a.Project != "p1" || !slices.Equal(a.Users, []string{"ada", "ayse"}) {
t.Errorf("deneme %+v", a)
}
if a := by["other-ops-x"]; !slices.Equal(a.Users, []string{"bob"}) {
t.Errorf("x %+v", a)
}
if a := by["test"]; a.Parent != "root" || a.Project != "" || len(a.Users) != 0 {
t.Errorf("org %+v", a)
}
if n := AccountName("Test", "arge", "Görüntü İşleme"); n != "test-arge-goruntu_isleme" {
t.Errorf("name %q", n)
}
// The first install's tree: one id for all three.
def := Accounts([]TenancyProject{{ID: "default", Name: "default", TeamID: "default", TeamName: "default",
OrgID: "default", OrgName: "default"}}, []TenancyMember{{UserID: "u", Scope: "project", ScopeID: "default"}},
map[string]string{"u": "admin2"})
if len(def) != 3 || def[2].Name != "default-default-default" || def[2].Parent != "default-default" ||
def[1].Parent != "default" || !slices.Equal(def[2].Users, []string{"admin2"}) {
t.Errorf("default tree %+v", def)
}
// Two that come out the same are told apart.
same := Accounts([]TenancyProject{
{ID: "a", Name: "ml", TeamID: "t", TeamName: "x", OrgID: "o", OrgName: "A"},
{ID: "b", Name: "ML", TeamID: "t", TeamName: "x", OrgID: "o", OrgName: "A"},
}, nil, nil)
if same[2].Name == same[3].Name {
t.Errorf("same name twice: %+v", same)
}
}
func TestParseJobs(t *testing.T) {
out := "41|ayse|test-arge-deneme|gpu|2026-11-15T10:00:00|2026-11-15T10:30:00|1800|billing=4,cpu=4,gres/gpu=1,mem=16G,node=1|COMPLETED\n" +
"42|ada|test-arge-deneme|gpu|2026-11-15T10:00:00|Unknown|0|cpu=2|RUNNING\n" +
"43|root|root|gpu|2026-11-15T09:00:00|2026-11-15T09:00:05|5|cpu=1,mem=1G|CANCELLED by 0\n"
jobs, err := ParseJobs(out)
if err != nil {
t.Fatal(err)
}
if len(jobs) != 2 {
t.Fatalf("jobs %+v", jobs)
}
j := jobs[0]
if j.ID != "41" || j.User != "ayse" || j.GPUs != 1 || j.CPUs != 4 || j.Elapsed != 30*time.Minute || j.State != "COMPLETED" {
t.Errorf("job %+v", j)
}
if jobs[1].State != "CANCELLED" {
t.Errorf("state %q", jobs[1].State)
}
if _, err := ParseJobs("short|line\n"); err == nil {
t.Error("a short line taken")
}
as := ParseAssociations("root||\ntest|ayse|test-arge\n")
if len(as) != 2 || as[1] != (Association{"test", "ayse", "test-arge"}) {
t.Errorf("assoc %+v", as)
}
}