layer1: add namespace manager summary

This commit is contained in:
Naeel
2026-04-26 10:55:56 +03:00
parent 67db8d71f1
commit 5c481b7293
5 changed files with 74 additions and 0 deletions
+27
View File
@@ -59,6 +59,10 @@ func TestNamespaceManagerSnapshotAndGet(t *testing.T) {
if record.Name != "tenant-a" || record.Phase != NamespacePhaseDiscovered {
t.Fatalf("unexpected record returned: %+v", record)
}
summary := manager.Summary()
if summary.TotalNamespaces != 2 {
t.Fatalf("expected summary total namespaces to be 2, got %d", summary.TotalNamespaces)
}
}
func TestNamespaceManagerUpsertIncrementsGeneration(t *testing.T) {
@@ -448,6 +452,29 @@ func TestPrepareManagedNamespaceWatcher(t *testing.T) {
}
}
func TestNamespaceManagerSummary(t *testing.T) {
manager := NewNamespaceManager()
manager.Upsert(NamespaceEvent{Type: NamespaceEventAdd, Name: "tenant-a", Source: NamespaceSourceWatcher})
manager.Upsert(NamespaceEvent{Type: NamespaceEventAdd, Name: "tenant-b", Source: NamespaceSourceWatcher})
_, _ = manager.MarkPartRegistering("tenant-a", "router")
manager.Upsert(NamespaceEvent{Type: NamespaceEventRemove, Name: "tenant-b", Source: NamespaceSourceWatcher})
manager.Subscribe(&testNamespaceSubscriber{name: "router"})
summary := manager.Summary()
if summary.TotalNamespaces != 2 {
t.Fatalf("expected total namespaces 2, got %d", summary.TotalNamespaces)
}
if summary.PhaseCounts[NamespacePhaseRegistering] != 1 {
t.Fatalf("expected one registering namespace")
}
if summary.PhaseCounts[NamespacePhaseRemoved] != 1 {
t.Fatalf("expected one removed namespace")
}
if !reflect.DeepEqual([]string{"router"}, summary.Subscribers) {
t.Fatalf("expected router subscriber in summary")
}
}
func TestNamespaceManagerDispatchAdd(t *testing.T) {
manager := NewNamespaceManager()
manager.Upsert(NamespaceEvent{Type: NamespaceEventAdd, Name: "tenant-a", Source: NamespaceSourceWatcher})