package reconciler import ( "testing" "time" "gitea.mynodes.xyz/ilker/llmgw/internal/control/catalog" ) func sharedCatalog(t *testing.T) *catalog.Catalog { t.Helper() mk := func(name, out string) catalog.Model { return catalog.Model{Name: name, Source: "/w/" + name + ".safetensors", ComfyUI: &catalog.ComfyUI{Environment: "art", Workflow: "flux-schnell", Output: out}, Scaling: catalog.Scaling{Max: 1, IdleTimeout: time.Hour}, Profiles: []catalog.Profile{{Name: "p", Engine: catalog.EngineComfyUI, GPUClass: "h100-80g", TP: 1}}} } cat, err := catalog.New([]catalog.Model{mk("flux", catalog.OutputPictures), mk("sf3d", catalog.OutputMeshes)}) if err != nil { t.Fatal(err) } return cat } func TestAMemberAskedForStartsItsEnvironmentsOneReplica(t *testing.T) { // A picture model and a 3D model on one card took turns, each from // nothing: in one environment, asking for either starts one replica // that serves both, and neither gets one of its own. h := newHarness(t, testModel(1), gpuNode("1", 1)) h.r.cat.Store(sharedCatalog(t)) if !h.r.Want("sf3d") { t.Fatal("a member was not wanted") } h.r.Reconcile(t.Context()) h.markReady() h.r.Want("flux") h.r.Reconcile(t.Context()) var models []string for _, rep := range h.r.Replicas() { if rep.State.Counts() { models = append(models, rep.Model) } } if len(models) != 1 || models[0] != "comfyui-env-art" { t.Fatalf("replicas %v", models) } // The member's sibling never evicts the replica serving it. reps := h.r.Replicas() h.r.RecordUsage(map[string]time.Time{reps[0].ID: h.clock.now()}) h.advance(DefaultConfig().MinLifetime + DefaultConfig().EvictionGrace + time.Minute) if got := h.r.evictable("flux"); len(got) != 0 { t.Errorf("a member was offered its own environment's replica: %+v", got) } if _, _, ok := h.r.WaitFor("flux"); ok { t.Error("a member served by a replica that is up was said to be waiting") } }