promote inbox message to a shared type

This commit is contained in:
Jay
2026-05-03 10:41:11 -04:00
parent ab641e8313
commit efdbf7b37f
10 changed files with 30 additions and 35 deletions
+4 -2
View File
@@ -24,6 +24,10 @@ type RetryConfig = transport.RetryConfig
type ConnectionOption = transport.ConnectionOption
type ConnectionStats = transport.ConnectionStats
// Common Types
type InboxMessage = types.InboxMessage
// Outbound Pool types
type OutboundPool = outbound.Pool
@@ -31,7 +35,6 @@ type OutboundPoolConfig = outbound.PoolConfig
type OutboundPoolOption = outbound.PoolOption
type OutboundWorkerConfig = outbound.WorkerConfig
type OutboundWorkerOption = outbound.WorkerOption
type OutboundInboxMessage = outbound.InboxMessage
type OutboundPoolEvent = outbound.PoolEvent
type OutboundPoolEventKind = outbound.PoolEventKind
type OutboundPoolStats = outbound.PoolStats
@@ -54,7 +57,6 @@ type InboundWorkerOption = inbound.WorkerOption
type InboundWorkerFactory = inbound.WorkerFactory
type InboundWorker = inbound.Worker
type InboundWorkerExitKind = inbound.WorkerExitKind
type InboundInboxMessage = inbound.InboxMessage
type InboundPoolEvent = inbound.PoolEvent
type InboundPoolEventKind = inbound.PoolEventKind
type InboundPoolStats = inbound.PoolStats
+4 -11
View File
@@ -9,7 +9,6 @@ import (
"log/slog"
"sync"
"sync/atomic"
"time"
)
// Types
@@ -55,14 +54,8 @@ type PeerStats struct {
Connection transport.ConnectionStats
}
type InboxMessage struct {
ID string
Data []byte
ReceivedAt time.Time
}
type PoolPlugin struct {
Inbox chan<- InboxMessage
Inbox chan<- types.InboxMessage
Events chan<- PoolEvent
Errors chan<- error
InboxCounter *atomic.Uint64
@@ -86,7 +79,7 @@ type Pool struct {
id string
peers map[string]*Peer
inbox chan InboxMessage
inbox chan types.InboxMessage
events chan PoolEvent
errors chan error
@@ -143,7 +136,7 @@ func NewPool(ctx context.Context, id string, config *PoolConfig, handler slog.Ha
cancel: cancel,
id: id,
peers: make(map[string]*Peer),
inbox: make(chan InboxMessage, config.InboxBufferSize),
inbox: make(chan types.InboxMessage, config.InboxBufferSize),
events: make(chan PoolEvent, config.EventsBufferSize),
errors: make(chan error, config.ErrorsBufferSize),
inboxCounter: &atomic.Uint64{},
@@ -166,7 +159,7 @@ func (p *Pool) Peers() []string {
return ids
}
func (p *Pool) Inbox() <-chan InboxMessage {
func (p *Pool) Inbox() <-chan types.InboxMessage {
return p.inbox
}
+2 -2
View File
@@ -252,7 +252,7 @@ func RunForwarder(
id string,
ctx context.Context,
messages <-chan types.ReceivedMessage,
inbox chan<- InboxMessage,
inbox chan<- types.InboxMessage,
workerProcessedCount *atomic.Uint64,
poolInboxCount *atomic.Uint64,
) {
@@ -268,7 +268,7 @@ func RunForwarder(
case <-ctx.Done():
return
case inbox <- InboxMessage{
case inbox <- types.InboxMessage{
ID: id,
Data: msg.Data,
ReceivedAt: msg.ReceivedAt,
+1 -1
View File
@@ -13,7 +13,7 @@ func TestRunForwarder(t *testing.T) {
t.Run("message passes through to inbox", func(t *testing.T) {
id := "wss://test"
messages := make(chan types.ReceivedMessage, 1)
inbox := make(chan InboxMessage, 1)
inbox := make(chan types.InboxMessage, 1)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
+4 -3
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"git.wisehodl.dev/jay/go-honeybee/honeybeetest"
"git.wisehodl.dev/jay/go-honeybee/transport"
"git.wisehodl.dev/jay/go-honeybee/types"
"github.com/gorilla/websocket"
"github.com/stretchr/testify/assert"
"sync"
@@ -19,7 +20,7 @@ type workerTestVars struct {
incoming chan honeybeetest.MockIncomingData
outgoing chan honeybeetest.MockOutgoingData
pool PoolPlugin
inbox chan InboxMessage
inbox chan types.InboxMessage
events chan PoolEvent
exitKind *atomic.Value
wg *sync.WaitGroup
@@ -36,7 +37,7 @@ func setupWorkerTest(t *testing.T) workerTestVars {
assert.NoError(t, err)
worker.cancel = cancel
inbox := make(chan InboxMessage, 256)
inbox := make(chan types.InboxMessage, 256)
events := make(chan PoolEvent, 10)
exitKind := &atomic.Value{}
@@ -134,7 +135,7 @@ func TestWorkerStart(t *testing.T) {
exitKind := &atomic.Value{}
var once sync.Once
pool := PoolPlugin{
Inbox: make(chan InboxMessage, 256),
Inbox: make(chan types.InboxMessage, 256),
Events: make(chan PoolEvent, 10),
OnExit: func(kind WorkerExitKind) {
once.Do(func() { exitKind.Store(kind) })
+4 -11
View File
@@ -8,7 +8,6 @@ import (
"log/slog"
"sync"
"sync/atomic"
"time"
)
// Types
@@ -42,15 +41,9 @@ type PeerStats struct {
Worker WorkerStats
}
type InboxMessage struct {
ID string
Data []byte
ReceivedAt time.Time
}
type PoolPlugin struct {
ID string
Inbox chan<- InboxMessage
Inbox chan<- types.InboxMessage
Events chan<- PoolEvent
Errors chan<- error
InboxCounter *atomic.Uint64
@@ -73,7 +66,7 @@ type Pool struct {
id string
peers map[string]*Peer
inbox chan InboxMessage
inbox chan types.InboxMessage
events chan PoolEvent
errors chan error
@@ -127,7 +120,7 @@ func NewPool(ctx context.Context, id string, config *PoolConfig, handler slog.Ha
cancel: cancel,
id: id,
peers: make(map[string]*Peer),
inbox: make(chan InboxMessage, config.InboxBufferSize),
inbox: make(chan types.InboxMessage, config.InboxBufferSize),
events: make(chan PoolEvent, config.EventsBufferSize),
errors: make(chan error, config.ErrorsBufferSize),
inboxCounter: &atomic.Uint64{},
@@ -150,7 +143,7 @@ func (p *Pool) Peers() []string {
return ids
}
func (p *Pool) Inbox() <-chan InboxMessage {
func (p *Pool) Inbox() <-chan types.InboxMessage {
return p.inbox
}
+2 -2
View File
@@ -407,7 +407,7 @@ func RunForwarder(
id string,
ctx context.Context,
messages <-chan types.ReceivedMessage,
inbox chan<- InboxMessage,
inbox chan<- types.InboxMessage,
workerProcessedCount *atomic.Uint64,
poolInboxCount *atomic.Uint64,
) {
@@ -423,7 +423,7 @@ func RunForwarder(
case <-ctx.Done():
return
case inbox <- InboxMessage{
case inbox <- types.InboxMessage{
ID: id,
Data: msg.Data,
ReceivedAt: msg.ReceivedAt,
+1 -1
View File
@@ -13,7 +13,7 @@ func TestRunForwarder(t *testing.T) {
t.Run("message passes through to inbox", func(t *testing.T) {
id := "wss://test"
messages := make(chan types.ReceivedMessage, 1)
inbox := make(chan InboxMessage, 1)
inbox := make(chan types.InboxMessage, 1)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
+2 -2
View File
@@ -16,13 +16,13 @@ import (
)
func makeWorkerContext(t *testing.T) (
inbox chan InboxMessage,
inbox chan types.InboxMessage,
events chan PoolEvent,
errors chan error,
pool PoolPlugin,
) {
t.Helper()
inbox = make(chan InboxMessage, 256)
inbox = make(chan types.InboxMessage, 256)
events = make(chan PoolEvent, 10)
errors = make(chan error, 10)
pool = PoolPlugin{
+6
View File
@@ -29,3 +29,9 @@ type ReceivedMessage struct {
Data []byte
ReceivedAt time.Time
}
type InboxMessage struct {
ID string
Data []byte
ReceivedAt time.Time
}