feat(sense): complete T-006 five-stream integration
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"yovision/sense/internal/device"
|
||||
)
|
||||
@@ -144,6 +145,42 @@ func TestLowerQuotaDoesNotDisableExistingStreams(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvergenceSnapshotAndRuntimeReconcileRequest(t *testing.T) {
|
||||
t.Parallel()
|
||||
store := openTestStore(t)
|
||||
ctx := context.Background()
|
||||
if err := store.EnsureSite(ctx, device.Site{TenantID: "tenant", ID: "site", Name: "Site"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := store.CreateDevice(ctx, videoDevice(1, "tenant", "site")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
now := time.Date(2026, 8, 7, 0, 0, 0, 0, time.UTC)
|
||||
if err := store.MarkReconciled(ctx, "camera-001", 1, now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := store.UpdateActualState(ctx, "camera-001", device.ActualOnline, now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
snapshot, err := store.ConvergenceSnapshot(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if snapshot.Total != 1 || snapshot.Unconverged != 0 {
|
||||
t.Fatalf("expected converged snapshot, got %+v", snapshot)
|
||||
}
|
||||
if err := store.RequestReconcile(ctx, "camera-001", now.Add(time.Second)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
snapshot, err = store.ConvergenceSnapshot(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if snapshot.Unconverged != 1 || snapshot.Devices[0].ObservedGeneration != 0 {
|
||||
t.Fatalf("runtime loss must invalidate convergence: %+v", snapshot)
|
||||
}
|
||||
}
|
||||
|
||||
func openTestStore(t *testing.T) *SQLite {
|
||||
t.Helper()
|
||||
dsn := "file:" + filepath.ToSlash(filepath.Join(t.TempDir(), "sense.db"))
|
||||
|
||||
Reference in New Issue
Block a user