Add timestamp to pool events.
This commit is contained in:
+3
-1
@@ -9,6 +9,7 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
@@ -34,6 +35,7 @@ type OnExitFunction func(kind WorkerExitKind)
|
|||||||
type PoolEvent struct {
|
type PoolEvent struct {
|
||||||
ID string
|
ID string
|
||||||
Kind PoolEventKind
|
Kind PoolEventKind
|
||||||
|
At time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type PoolStats struct {
|
type PoolStats struct {
|
||||||
@@ -374,7 +376,7 @@ func (p *Pool) addLocked(id string, socket types.Socket) error {
|
|||||||
conn.Close()
|
conn.Close()
|
||||||
|
|
||||||
select {
|
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():
|
case <-p.ctx.Done():
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func expectEvent(
|
|||||||
honeybeetest.Eventually(t, func() bool {
|
honeybeetest.Eventually(t, func() bool {
|
||||||
select {
|
select {
|
||||||
case e := <-events:
|
case e := <-events:
|
||||||
return e.ID == expectedURL && e.Kind == expectedKind
|
return e.ID == expectedURL && e.Kind == expectedKind && !e.At.IsZero()
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
@@ -22,6 +23,7 @@ const (
|
|||||||
type PoolEvent struct {
|
type PoolEvent struct {
|
||||||
ID string
|
ID string
|
||||||
Kind PoolEventKind
|
Kind PoolEventKind
|
||||||
|
At time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type PoolStats struct {
|
type PoolStats struct {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func expectEvent(
|
|||||||
honeybeetest.Eventually(t, func() bool {
|
honeybeetest.Eventually(t, func() bool {
|
||||||
select {
|
select {
|
||||||
case e := <-events:
|
case e := <-events:
|
||||||
return e.ID == expectedURL && e.Kind == expectedKind
|
return e.ID == expectedURL && e.Kind == expectedKind && !e.At.IsZero()
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -261,7 +261,7 @@ func (s *Session) Start(
|
|||||||
|
|
||||||
// set up new connection
|
// set up new connection
|
||||||
s.connPtr.Store(conn)
|
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
|
// set up session context
|
||||||
sctx, scancel := context.WithCancel(ctx)
|
sctx, scancel := context.WithCancel(ctx)
|
||||||
@@ -296,7 +296,7 @@ func (s *Session) Start(
|
|||||||
|
|
||||||
// tear down connection
|
// tear down connection
|
||||||
s.connPtr.Store(nil)
|
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
|
// exit if worker is shutting down
|
||||||
select {
|
select {
|
||||||
|
|||||||
Reference in New Issue
Block a user