summaryrefslogtreecommitdiff
path: root/internal/statsengine/engine_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-13 14:41:28 +0300
committerPaul Buetow <paul@buetow.org>2026-05-13 14:41:28 +0300
commitde3405c275898c8cd528a636dbd40e1b685cfaa5 (patch)
tree53711959800677aa694e18331476add24a21b8ef /internal/statsengine/engine_test.go
parentd392eebe5bd127e1573734321b0cabaad4182d7c (diff)
use errgroup instead of WaitGroup for concurrent snapshot builders
Replace sync.WaitGroup with errgroup.Group in buildSubSnapshots so errors from sub-builders (buildSyscallSnapshots, buildFileSnapshots, buildProcessSnapshots, buildHistogramSnapshot) are captured and propagated rather than silently dropped. Change Engine.Snapshot() to return (*Snapshot, error), update runtime.SnapshotSource and dashboard.SnapshotSource interfaces accordingly, and adjust all callers in tui.go, dashboard/model.go, and the test helpers. Each sub-builder now returns (result, error); the error return is currently always nil but establishes the contract for future validation. The per-type Snapshot() convenience methods (histogram, syscall, file, process) panic on error since they are internal helpers where failure would be a programming bug. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/statsengine/engine_test.go')
-rw-r--r--internal/statsengine/engine_test.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/internal/statsengine/engine_test.go b/internal/statsengine/engine_test.go
index 7ba8c3a..f714844 100644
--- a/internal/statsengine/engine_test.go
+++ b/internal/statsengine/engine_test.go
@@ -33,7 +33,10 @@ func TestEngineIngestAndSnapshotIntegration(t *testing.T) {
engine.Ingest(newEnginePair(types.SYS_ENTER_COPY_FILE_RANGE, 80, types.TRANSFER_CLASSIFIED, "proc-b", 2, "/tmp/b", 20, 40, 8))
clock.Advance(1 * time.Second)
- snap := engine.Snapshot()
+ snap, err := engine.Snapshot()
+ if err != nil {
+ t.Fatalf("unexpected snapshot error: %v", err)
+ }
if snap == nil {
t.Fatalf("expected snapshot")
}
@@ -79,7 +82,10 @@ func TestEngineSnapshotWithNoEvents(t *testing.T) {
clock := &fakeClock{now: time.Unix(2000, 0)}
engine := newEngineWithClock(10, clock.Now)
- snap := engine.Snapshot()
+ snap, err := engine.Snapshot()
+ if err != nil {
+ t.Fatalf("unexpected snapshot error: %v", err)
+ }
if snap == nil {
t.Fatalf("expected snapshot")
}