package reconciler import ( "testing" ) type fixedLeader bool func (f fixedLeader) IsLeader() bool { return bool(f) } func TestAStandbyPlacesNothing(t *testing.T) { // The failure this prevents: two control planes against one store both see // a model wanting replicas and none running, and both place. The model // ends up with twice what it asked for, each replica holding GPUs the // other's inventory believes are free, and nothing crashes to say so. h := newHarness(t, testModel(1), gpuNode("n1", 8)) h.r.SetLeadership(fixedLeader(false)) h.r.Reconcile(t.Context()) if got := len(h.r.Replicas()); got != 0 { t.Errorf("a standby placed %d replicas", got) } } func TestALeaderPlacesAsBefore(t *testing.T) { h := newHarness(t, testModel(1), gpuNode("n1", 8)) h.r.SetLeadership(fixedLeader(true)) h.r.Reconcile(t.Context()) if got := len(h.r.Replicas()); got == 0 { t.Error("a leader placed nothing") } } func TestWithoutLeadershipConfiguredNothingChanges(t *testing.T) { // Every single-control-plane deployment, and every test written before // leadership existed. Unset must mean "act", not "wait for permission // from a thing that was never wired up". h := newHarness(t, testModel(1), gpuNode("n1", 8)) h.r.Reconcile(t.Context()) if got := len(h.r.Replicas()); got == 0 { t.Error("a reconciler with no leadership configured placed nothing") } }