test(unifiedresources): benchmark dirty view rebuilds

Separate full-cache rebuild cost after a one-resource invalidation from the clean cached-read benchmark for comparable lock-path evaluation.

Change-source: pulse-maintainer
This commit is contained in:
pulse-triage[bot]
2026-09-23 18:15:10 +01:00
parent d09d8d76e6
commit e01d6461ef
@@ -46,6 +46,58 @@ func BenchmarkRegistry_CachedVMReads(b *testing.B) {
}
}
// BenchmarkRegistry_DirtyVMCacheRead measures the invalidation path after a
// one-resource update: the next typed accessor must rebuild the 1,000-VM view
// before it can return. This is intentionally separate from the clean-cache
// read benchmark so rebuild cost is not mistaken for accessor lock cost.
func BenchmarkRegistry_DirtyVMCacheRead(b *testing.B) {
const count = 1000
records := make([]IngestRecord, count)
for i := range records {
records[i] = IngestRecord{
SourceID: fmt.Sprintf("vm-%d", i),
Resource: Resource{
Type: ResourceTypeVM,
Name: fmt.Sprintf("vm-%d", i),
Status: StatusOnline,
},
}
}
registry := NewRegistry(nil)
registry.IngestRecords(SourceProxmox, records)
if got := len(registry.VMs()); got != count {
b.Fatalf("VM cache length = %d, want %d", got, count)
}
update := IngestRecord{
SourceID: "vm-0",
Resource: Resource{
Type: ResourceTypeVM,
Name: "vm-0",
Status: StatusOnline,
},
}
registry.IngestRecords(SourceProxmox, []IngestRecord{update})
if got := len(registry.VMs()); got != count {
b.Fatalf("VM count after update = %d, want %d", got, count)
}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
if i%2 == 0 {
update.Resource.Status = StatusOnline
} else {
update.Resource.Status = StatusOffline
}
registry.IngestRecords(SourceProxmox, []IngestRecord{update})
if got := len(registry.VMs()); got != count {
b.Fatalf("VM count after update = %d, want %d", got, count)
}
}
}
// BenchmarkIngestRecords_NewResources measures the ingest path when every
// record creates a new resource (no dedup). This is the baseline cost of
// ingestion: ID generation, map insertion, identity indexing, and child