feat(work): add graph admission scheduler
CI / test (push) Successful in 22s

This commit is contained in:
m
2026-08-22 13:31:39 +03:00
parent b2f922cbbc
commit 4a800df1e1
4 changed files with 108 additions and 2 deletions
+23
View File
@@ -33,3 +33,26 @@ func TestWorkGraphKeepsDependentNodeBlocked(t *testing.T) {
t.Fatalf("dependent node became ready early: %#v %v", ready, err)
}
}
func TestGraphSchedulerEnforcesParallelBudgetAndExplicitConflict(t *testing.T) {
graph := work.WorkGraph{ID: "graph-1", Revision: 1, State: work.GraphDraft, Budget: work.GraphBudget{MaxParallel: 2, MaxAttempts: 2}, Nodes: []work.GraphNode{
{ID: "b", IdempotencyKey: "b-key", State: work.GraphNodeReady},
{ID: "a", IdempotencyKey: "a-key", State: work.GraphNodeReady},
}}
admitted, err := workdomain.AdmitGraph(graph)
if err != nil || admitted.State != work.GraphAdmitted {
t.Fatalf("graph was not admitted: %#v %v", admitted, err)
}
ready, err := workdomain.ScheduleReadyNodes(admitted, 1)
if err != nil || len(ready) != 1 || ready[0] != "a" {
t.Fatalf("scheduler ignored parallel budget/order: %#v %v", ready, err)
}
conflict := work.ConflictSet{ID: "conflict-1", GraphID: "graph-1", GraphRevision: 1, NodeID: "a", CandidateIDs: []string{"candidate-b", "candidate-a"}}
resolved, err := workdomain.ResolveGraphConflict(conflict, "candidate-a")
if err != nil || !resolved.Resolved || resolved.CandidateIDs[0] != "candidate-a" {
t.Fatalf("conflict was not explicitly resolved: %#v %v", resolved, err)
}
if _, err := workdomain.ResolveGraphConflict(conflict, "unknown"); err != workdomain.ErrConflictUnresolved {
t.Fatalf("unknown candidate was accepted: %v", err)
}
}