summaryrefslogtreecommitdiff
path: root/internal/eventloop_error_handling_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-18 08:51:33 +0200
committerPaul Buetow <paul@buetow.org>2026-03-18 08:51:33 +0200
commit6ab80599c8f8ba688a0415ecbeb03e494ef31f04 (patch)
treec0c831f29bddb1754629eb337f5ec8bc9efae983 /internal/eventloop_error_handling_test.go
parentd8ef4ac43d3039c3d583c1ac20c7dca6b69a6c92 (diff)
refactor: replace reflect.TypeOf dispatch in exit handlers with type switch (task 432)
The exitHandlers map keyed by reflect.Type was a reflection-based dispatch table that incurred allocation and reflection overhead on every event pair in the hot processing path. Replace it with a plain type switch in handleTracepointExit, which the compiler resolves statically. Removes: initExitHandlers, typeKey, mustBeType, newTypedExitHandler, exitHandlerRegistry, the exitHandlers struct field, and the tracepointExitHandler type alias — all dead after the switch. Fixes a pre-existing uint→uint64 mismatch in stats(). Updates tests to target the new default branch directly. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'internal/eventloop_error_handling_test.go')
-rw-r--r--internal/eventloop_error_handling_test.go46
1 files changed, 20 insertions, 26 deletions
diff --git a/internal/eventloop_error_handling_test.go b/internal/eventloop_error_handling_test.go
index b7dd282..5867417 100644
--- a/internal/eventloop_error_handling_test.go
+++ b/internal/eventloop_error_handling_test.go
@@ -166,44 +166,38 @@ func TestDecodeRawEventMalformedNotifies(t *testing.T) {
}
}
-func TestMustBeTypeReturnsTypedEnterEvent(t *testing.T) {
- el := mustNewEventLoop(t, eventLoopConfig{})
- enterEv, enterRaw := makeEnterOpenEvent(t, defaulTime, defaultPid, defaultTid)
- ep := event.NewPair(types.NewOpenEvent(enterRaw))
- defer ep.Recycle()
-
- typed, ok := mustBeType[*types.OpenEvent](el, ep, "ignored")
- if !ok {
- t.Fatal("expected mustBeType to return the typed enter event")
- }
- if typed.GetTid() != enterEv.Tid {
- t.Fatalf("mustBeType() returned tid %d, want %d", typed.GetTid(), enterEv.Tid)
- }
-}
-
-func TestMustBeTypeRecyclesMalformedPairAndNotifies(t *testing.T) {
+// unknownEvent is a minimal event.Event stub used to exercise the default
+// branch of handleTracepointExit (an enter-event type not covered by any case).
+type unknownEvent struct{}
+
+func (unknownEvent) String() string { return "unknownEvent" }
+func (unknownEvent) GetTraceId() types.TraceId { return 0 }
+func (unknownEvent) GetPid() uint32 { return 0 }
+func (unknownEvent) GetTid() uint32 { return 0 }
+func (unknownEvent) GetTime() uint64 { return 0 }
+func (unknownEvent) Equals(other any) bool { return false }
+func (unknownEvent) Recycle() {}
+
+func TestHandleTracepointExitUnknownTypeDropsMalformedEvent(t *testing.T) {
el := mustNewEventLoop(t, eventLoopConfig{})
warnings := make(chan string, 1)
el.warningCb = func(message string) { warnings <- message }
- _, enterRaw := makeEnterNullEvent(t, defaulTime, defaultPid, defaultTid, types.SYS_ENTER_SYNC)
- ep := event.NewPair(types.NewNullEvent(enterRaw))
+ // Wrap an unknown enter-event type to hit the default branch of the type switch.
+ ep := event.NewPair(unknownEvent{})
- typed, ok := mustBeType[*types.OpenEvent](el, ep, "Dropped malformed open enter event")
- if ok || typed != nil {
- t.Fatalf("expected mustBeType mismatch to fail, got ok=%v typed=%v", ok, typed)
- }
- if ep.EnterEv != nil || ep.ExitEv != nil {
- t.Fatalf("expected malformed pair to be recycled")
+ ok := el.handleTracepointExit(ep)
+ if ok {
+ t.Fatal("expected handleTracepointExit to return false for unknown enter-event type")
}
select {
case msg := <-warnings:
- if msg != "Dropped malformed open enter event" {
+ if msg != "Dropped malformed enter event" {
t.Fatalf("unexpected warning %q", msg)
}
default:
- t.Fatalf("expected warning notification")
+ t.Fatal("expected warning notification for unknown enter-event type")
}
}