test: NoticeHandler observer notified

This commit is contained in:
Jay
2026-06-03 15:19:42 -04:00
parent 9d4873f8d4
commit cf4a2d380a
2 changed files with 17 additions and 4 deletions
+6 -1
View File
@@ -60,11 +60,16 @@ func (h *NoticeHandler) route() {
if err != nil {
continue
}
now := time.Now()
h.notices <- Notice{
PeerID: msg.ID,
Message: message,
Timestamp: time.Now(),
Timestamp: now,
}
h.envoy.Observer().Record(msg.ID, NoticeReceived{
Message: message,
At: now,
})
}
}
}
+11 -3
View File
@@ -48,9 +48,17 @@ func TestNoticeHandler(t *testing.T) {
})
t.Run("observer notified", func(t *testing.T) {
// wire mockObserver via envoy (requires constructor option or mock envoy)
// p.receive(envelope.EncloseNotice("hello"))
// Eventually: mockObserver recorded NoticeReceived{Message: "hello"}
obs := &mockObserver{}
p, envoy := newMockEnvoy(t, WithEmbassyObserver(obs))
h := NewNoticeHandler(envoy)
t.Cleanup(h.Close)
p.receive([]byte(envelope.EncloseNotice("hello")))
Eventually(t, func() bool {
events := EventsOf[NoticeReceived](obs)
return len(events) == 1 && events[0].Message == "hello"
}, "NoticeReceived observable not recorded")
})
t.Run("close cleans up", func(t *testing.T) {