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