opensnitch/daemon/dns/event_stats_test.go
trvon 0be4f7c4c4
daemon: event-loss diagnostics via per-module event_stats counters
Add fixed-size, process-lifetime counters (received/enqueued/dropped/
drained/dequeued/decoded/decode-errors/reader-errors/canceled) for the
process and DNS eBPF event paths, exposed as individually-atomic
snapshots. Wire DNSEventCounters and ProcessEventCounters through the
perf reader/enqueue/decode loop in daemon/dns and daemon/procmon/ebpf,
with a matching ebpf_prog/event_stats.h and a structural eBPF test.
Counters hold totals only, never event payloads.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-05 16:58:11 -07:00

31 lines
995 B
Go

package dns
import (
"testing"
"github.com/evilsocket/opensnitch/daemon/core"
)
func TestEventDNSWorkerDiagnostics(t *testing.T) {
before := core.DNSEventCounters.Snapshot()
q := make(chan []byte, 1)
// Existing trace logging slices the first 20 bytes before binary.Read; use a
// short record safe for that logging, without altering the existing parser.
q <- make([]byte, 20)
close(q)
exit := make(chan struct{}, 1)
dnsWorker(0, q, exit)
after := core.DNSEventCounters.Snapshot()
if after.Dequeued-before.Dequeued != 1 || after.DecodeErrors-before.DecodeErrors != 1 || after.Decoded != before.Decoded {
t.Fatalf("before=%+v after=%+v", before, after)
}
q = make(chan []byte, 1)
q <- nil
close(q)
exit <- struct{}{}
dnsWorker(0, q, exit)
final := core.DNSEventCounters.Snapshot()
if final.Canceled-after.Canceled != 1 || final.Dequeued-after.Dequeued != 1 || final.DecodeErrors != after.DecodeErrors {
t.Fatalf("cancellation: before=%+v after=%+v", after, final)
}
}