From c87a8cce6f51ef7b74d7429e33f343ab1969a9a3 Mon Sep 17 00:00:00 2001 From: Jay Date: Wed, 6 May 2026 15:23:30 -0400 Subject: [PATCH] Add timestamp to pool events. --- inbound/pool.go | 4 +++- inbound/pool_test.go | 2 +- outbound/pool.go | 2 ++ outbound/pool_test.go | 2 +- outbound/worker.go | 4 ++-- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/inbound/pool.go b/inbound/pool.go index 3242980..95b004b 100644 --- a/inbound/pool.go +++ b/inbound/pool.go @@ -9,6 +9,7 @@ import ( "log/slog" "sync" "sync/atomic" + "time" ) // Types @@ -34,6 +35,7 @@ type OnExitFunction func(kind WorkerExitKind) type PoolEvent struct { ID string Kind PoolEventKind + At time.Time } type PoolStats struct { @@ -374,7 +376,7 @@ func (p *Pool) addLocked(id string, socket types.Socket) error { conn.Close() select { - case p.events <- PoolEvent{ID: id, Kind: workerToPoolEvent[kind]}: + case p.events <- PoolEvent{ID: id, Kind: workerToPoolEvent[kind], At: time.Now()}: case <-p.ctx.Done(): return } diff --git a/inbound/pool_test.go b/inbound/pool_test.go index 7a135bd..aa5e19c 100644 --- a/inbound/pool_test.go +++ b/inbound/pool_test.go @@ -30,7 +30,7 @@ func expectEvent( honeybeetest.Eventually(t, func() bool { select { case e := <-events: - return e.ID == expectedURL && e.Kind == expectedKind + return e.ID == expectedURL && e.Kind == expectedKind && !e.At.IsZero() default: return false } diff --git a/outbound/pool.go b/outbound/pool.go index 658c2ce..27e1db0 100644 --- a/outbound/pool.go +++ b/outbound/pool.go @@ -8,6 +8,7 @@ import ( "log/slog" "sync" "sync/atomic" + "time" ) // Types @@ -22,6 +23,7 @@ const ( type PoolEvent struct { ID string Kind PoolEventKind + At time.Time } type PoolStats struct { diff --git a/outbound/pool_test.go b/outbound/pool_test.go index acb69ae..0583a4b 100644 --- a/outbound/pool_test.go +++ b/outbound/pool_test.go @@ -36,7 +36,7 @@ func expectEvent( honeybeetest.Eventually(t, func() bool { select { case e := <-events: - return e.ID == expectedURL && e.Kind == expectedKind + return e.ID == expectedURL && e.Kind == expectedKind && !e.At.IsZero() default: return false } diff --git a/outbound/worker.go b/outbound/worker.go index 8ac0132..492b42f 100644 --- a/outbound/worker.go +++ b/outbound/worker.go @@ -261,7 +261,7 @@ func (s *Session) Start( // set up new connection s.connPtr.Store(conn) - pool.Events <- PoolEvent{ID: s.id, Kind: EventConnected} + pool.Events <- PoolEvent{ID: s.id, Kind: EventConnected, At: time.Now()} // set up session context sctx, scancel := context.WithCancel(ctx) @@ -296,7 +296,7 @@ func (s *Session) Start( // tear down connection s.connPtr.Store(nil) - pool.Events <- PoolEvent{ID: s.id, Kind: EventDisconnected} + pool.Events <- PoolEvent{ID: s.id, Kind: EventDisconnected, At: time.Now()} // exit if worker is shutting down select {