- Add status_provider_test.go for queue status coverage - Update model_queue.go with queue simplification - Update run_dispatch.go with dispatch logic improvements - Update status_provider.go with status tracking - Update server tests for a2a, openai, and opsconsole - Remove archived PLAN and CODE_REVIEW documents for 02+01 surface snapshot contract - Archive 02+01_surface_snapshot_contract to 2026/06
133 lines
3.1 KiB
Go
133 lines
3.1 KiB
Go
package service
|
|
|
|
import (
|
|
"testing"
|
|
|
|
edgeevents "iop/apps/edge/internal/events"
|
|
edgenode "iop/apps/edge/internal/node"
|
|
"iop/packages/go/config"
|
|
)
|
|
|
|
func TestListNodeSnapshotsUsesEdgeQueueState(t *testing.T) {
|
|
reg := edgenode.NewRegistry()
|
|
reg.Register(&edgenode.NodeEntry{NodeID: "node-q-1", Alias: "node-q-1"})
|
|
|
|
store := edgenode.NewNodeStore()
|
|
rec := &edgenode.NodeRecord{
|
|
ID: "node-q-1",
|
|
Adapters: config.AdaptersConf{
|
|
OllamaInstances: []config.OllamaInstanceConf{
|
|
{
|
|
Name: "ollama-inst",
|
|
Enabled: true,
|
|
Capacity: 3,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
store.Add(rec)
|
|
|
|
bus := edgeevents.NewBus()
|
|
svc := New(reg, bus)
|
|
svc.SetNodeStore(store)
|
|
|
|
// Manually inject group state to modelQueueManager
|
|
svc.queue.mu.Lock()
|
|
svc.queue.groups["test-group"] = &modelQueueGroup{
|
|
key: "test-group",
|
|
adapter: "ollama-inst",
|
|
inflight: map[string]int{"node-q-1": 2},
|
|
queue: []*queueItem{
|
|
{
|
|
candidates: []candidateNode{
|
|
{entry: reg.All()[0], capacity: 3},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
svc.queue.mu.Unlock()
|
|
|
|
snaps := svc.ListNodeSnapshots()
|
|
if len(snaps) != 1 {
|
|
t.Fatalf("expected 1 node snapshot, got %d", len(snaps))
|
|
}
|
|
snap := snaps[0]
|
|
if len(snap.ProviderSnapshots) != 1 {
|
|
t.Fatalf("expected 1 provider snapshot, got %d", len(snap.ProviderSnapshots))
|
|
}
|
|
p := snap.ProviderSnapshots[0]
|
|
if p.Adapter != "ollama-inst" {
|
|
t.Errorf("expected adapter ollama-inst, got %s", p.Adapter)
|
|
}
|
|
if p.Capacity != 3 {
|
|
t.Errorf("expected capacity 3, got %d", p.Capacity)
|
|
}
|
|
if p.InFlight != 2 {
|
|
t.Errorf("expected inflight 2, got %d", p.InFlight)
|
|
}
|
|
if p.Queued != 1 {
|
|
t.Errorf("expected queued 1, got %d", p.Queued)
|
|
}
|
|
}
|
|
|
|
func TestListNodeSnapshotsTypeRouteSingleNamedInstance(t *testing.T) {
|
|
reg := edgenode.NewRegistry()
|
|
reg.Register(&edgenode.NodeEntry{NodeID: "node-q-2", Alias: "node-q-2"})
|
|
|
|
store := edgenode.NewNodeStore()
|
|
rec := &edgenode.NodeRecord{
|
|
ID: "node-q-2",
|
|
Adapters: config.AdaptersConf{
|
|
OllamaInstances: []config.OllamaInstanceConf{
|
|
{
|
|
Name: "ollama-local",
|
|
Enabled: true,
|
|
Capacity: 5,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
store.Add(rec)
|
|
|
|
bus := edgeevents.NewBus()
|
|
svc := New(reg, bus)
|
|
svc.SetNodeStore(store)
|
|
|
|
// Manually inject group state to modelQueueManager with type-name route "ollama"
|
|
svc.queue.mu.Lock()
|
|
svc.queue.groups["test-group"] = &modelQueueGroup{
|
|
key: "test-group",
|
|
adapter: "ollama",
|
|
inflight: map[string]int{"node-q-2": 3},
|
|
queue: []*queueItem{
|
|
{
|
|
candidates: []candidateNode{
|
|
{entry: reg.All()[0], capacity: 5},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
svc.queue.mu.Unlock()
|
|
|
|
snaps := svc.ListNodeSnapshots()
|
|
if len(snaps) != 1 {
|
|
t.Fatalf("expected 1 node snapshot, got %d", len(snaps))
|
|
}
|
|
snap := snaps[0]
|
|
if len(snap.ProviderSnapshots) != 1 {
|
|
t.Fatalf("expected 1 provider snapshot, got %d", len(snap.ProviderSnapshots))
|
|
}
|
|
p := snap.ProviderSnapshots[0]
|
|
if p.Adapter != "ollama-local" {
|
|
t.Errorf("expected adapter ollama-local, got %s", p.Adapter)
|
|
}
|
|
if p.Capacity != 5 {
|
|
t.Errorf("expected capacity 5, got %d", p.Capacity)
|
|
}
|
|
if p.InFlight != 3 {
|
|
t.Errorf("expected inflight 3, got %d", p.InFlight)
|
|
}
|
|
if p.Queued != 1 {
|
|
t.Errorf("expected queued 1, got %d", p.Queued)
|
|
}
|
|
}
|