Make consumers optional: a URL enables its mode, empty disables it
OLLAMA_URL and COMFY_URL no longer have defaults; each consumer (listener, client, startup probe, lock participation) is enabled by setting its URL and disabled by leaving it empty. At least one must be set. Ollama-only mode is a pure pass-through; ComfyUI-only mode skips the unload and warm-reload steps. /metrics is now served on both listeners. This is the extension pattern for future consumers such as local game detection.
This commit is contained in:
@@ -451,3 +451,82 @@ func TestLLMBusyWaitTimeoutRetryAfter(t *testing.T) {
|
||||
t.Fatalf("Retry-After = %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestComfyOnlyModeSkipsOllama(t *testing.T) {
|
||||
f := newFakes(t)
|
||||
|
||||
comfyClient, err := comfy.New(f.comfy.URL, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
comfyClient.PollInterval = 5 * time.Millisecond
|
||||
srv, err := New(Config{
|
||||
ComfyURL: f.comfy.URL,
|
||||
Lock: lock.New(nil),
|
||||
Comfy: comfyClient,
|
||||
Metrics: metrics.New(),
|
||||
JobTimeout: 2 * time.Second,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
front := httptest.NewServer(srv.ComfyHandler())
|
||||
defer front.Close()
|
||||
|
||||
resp, err := http.Post(front.URL+"/prompt", "application/json", strings.NewReader(`{}`))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
resp.Body.Close()
|
||||
if resp.StatusCode != 200 {
|
||||
t.Fatalf("prompt status = %d", resp.StatusCode)
|
||||
}
|
||||
f.completeJob()
|
||||
select {
|
||||
case <-f.freeCh:
|
||||
case <-time.After(3 * time.Second):
|
||||
t.Fatal("/free never called")
|
||||
}
|
||||
// With Ollama disabled the unload steps must not happen.
|
||||
if i := f.rec.index("unload"); i >= 0 {
|
||||
f.rec.mu.Lock()
|
||||
t.Fatalf("unload called with ollama disabled; events: %v", f.rec.events)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOllamaOnlyMode(t *testing.T) {
|
||||
f := newFakes(t)
|
||||
|
||||
ollamaClient, err := ollama.New(f.ollama.URL, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
srv, err := New(Config{
|
||||
OllamaURL: f.ollama.URL,
|
||||
Lock: lock.New(nil),
|
||||
Ollama: ollamaClient,
|
||||
Metrics: metrics.New(),
|
||||
LLMWaitTimeout: time.Second,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
front := httptest.NewServer(srv.OllamaHandler())
|
||||
defer front.Close()
|
||||
|
||||
resp, err := http.Post(front.URL+"/api/chat", "application/json", strings.NewReader(`{}`))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
resp.Body.Close()
|
||||
if resp.StatusCode != 200 {
|
||||
t.Fatalf("chat status = %d", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewRequiresConsumer(t *testing.T) {
|
||||
_, err := New(Config{Lock: lock.New(nil), Metrics: metrics.New()})
|
||||
if err == nil {
|
||||
t.Fatal("New with no upstream URLs should fail")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user