package assigngraph import ( "slices" "testing" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" ) // Design 47 G ยง272 (AS10), A-323: a cycle among the waits is found within one step and across steps, each edge's step named across // steps; a chain and provisioning edges are none. func TestACycleAmongTheWaitsWithinOrAcrossStepsIsFound(t *testing.T) { act := func(node, module, step string) meshwants.Edge { return meshwants.Edge{Kind: EdgeActing, Node: node, Module: module, Step: step} } entry := func(module string, edges ...meshwants.Edge) meshwants.AssignmentEntry { return meshwants.AssignmentEntry{Node: "ace", Module: module, Edges: edges} } for _, c := range []struct { name string entries []meshwants.AssignmentEntry want []string }{ {"two parts on each other in one step", []meshwants.AssignmentEntry{entry("a", act("ace", "b", "compose")), entry("b", act("ace", "a", "compose"))}, []string{"compose: ace/a -> ace/b -> ace/a"}}, {"three in a ring, said once", []meshwants.AssignmentEntry{entry("c", act("ace", "a", "build")), entry("a", act("ace", "b", "build")), entry("b", act("ace", "c", "build"))}, []string{"build: ace/a -> ace/b -> ace/c -> ace/a"}}, {"the indexer taking in the checker, the checker checking the indexer", []meshwants.AssignmentEntry{entry("checker", act("ace", "indexer", "take-in")), entry("indexer", act("ace", "checker", "check"))}, []string{"ace/checker -[take-in]-> ace/indexer -[check]-> ace/checker"}}, {"the assigner and the node-engine, across compose and place", []meshwants.AssignmentEntry{entry("assigner", act("ace", "engine", "compose")), entry("engine", act("ace", "assigner", "place")), entry("app", act("ace", "engine", "compose"), act("ace", "assigner", "place"))}, []string{"ace/assigner -[compose]-> ace/engine -[place]-> ace/assigner"}}, {"a chain", []meshwants.AssignmentEntry{entry("a", act("ace", "b", "compose")), entry("b", act("ace", "c", "compose")), entry("c")}, nil}, {"provisioning edges are no wait of a step", []meshwants.AssignmentEntry{entry("a", meshwants.Edge{Kind: EdgeProvisioning, Node: "ace", Module: "b"}), entry("b", meshwants.Edge{Kind: EdgeProvisioning, Node: "ace", Module: "a"})}, nil}, } { if got := Cycles(c.entries); !slices.Equal(got, c.want) { t.Errorf("%s: cycles %v, want %v", c.name, got, c.want) } } } // A-323, A-330: the node-engine on a node is read from the acting edges' seat, and the cycles that hold a want are those of the // edges said to hold it, each from the entry, naming each edge's step. func TestTheHeldCyclesAreThoseOfTheHoldingEdges(t *testing.T) { entries := []meshwants.AssignmentEntry{ {Node: "ace", Module: "assigner", Edges: []meshwants.Edge{{Kind: EdgeActing, Node: "ace", Module: "engine", Step: "compose", Seat: "node-engine"}}}, {Node: "ace", Module: "engine", Edges: []meshwants.Edge{{Kind: EdgeActing, Node: "ace", Module: "assigner", Step: "place", Seat: "mesh-wants"}}}, } if got := Engines(entries); len(got) != 1 || got["ace"] != "engine" { t.Errorf("the node-engines %v, want engine on ace", got) } all := func(meshwants.AssignmentEntry, meshwants.Edge) bool { return true } if got := HeldCycles(entries, all); len(got) != 2 || got["ace/engine"] != "ace/engine -[place]-> ace/assigner -[compose]-> ace/engine" { t.Errorf("held cycles %v", got) } // the node-engine's want held by no acting edge: no cycle holds anything if got := HeldCycles(entries, func(e meshwants.AssignmentEntry, _ meshwants.Edge) bool { return e.Module != "engine" }); len(got) != 0 { t.Errorf("held cycles with the node-engine's edges holding nothing: %v", got) } }